Pease help ASAP
C programming course. Cannot use global variables.
This is the assignment:
In this project you will calculate the maximum profit you could have made by trading a single stock over a period of one month. You will assume that you bought rounded stock units (usually in hundreds, or tens) worth between $3000 and $5000 at the best possible“closing” price during the period and sold it at the best possible “closing” price. You will assume that you are permitted to buy your units just once during this period and then sell it just once. You have to buy them before you can sell them (long trading only, no shorts).
I need help coding these two functions:
double getMinPrice(double* pPrices, int size);
scans the array for the lowest value and returns the the minimum price as a double.
double getMaxPrice(double* pPrices, int size);
Scans the array for the highest value and returns the maximum price as a double.
I have created a .txt in my project folder containing these values: (closing price of the stock CRON)
7.7
7.7
7.42
7.05
6.8
7.78
8.11
7.63
8.34
8.52
9.71
10.72
10.65
11.52
11.74
9.86
9.05
9.6
9.34
9.7
9.77
10.22
10.69
10.72
11.32
This is my code so far. Please show me how to creat those two functions. the max and min. they have to be verbaitum.
#define _CRT_SECURE_NO_WARNINGS
#define _NUMB_OF_STOCKS 30
#include <stdio.h>
#include <string.h>
void banner();
void readPrices();// char* fileName, int pricesCapacity, double* pPrices, int* pricesSize);
/*double getMinPrice(double* pPrices, int size);
double getMaxPrice(double* pPrices, int size);
void profitableTrades(double* pPrices, int pricesSize, double* pProfits, int* pProfitsSize);
void save(char* filename, double* pProfits, int profitsSize);
void print(double* pProfits, int profitsSize);*/
void banner() {
printf("Welcome to Stock Trading \n");
printf("xxxxxxxxxxxxxxxxxxxxxxxx\n\n");
}
void readPrices() {
char prices[_NUMB_OF_STOCKS];
char* stockPrices = "prices.txt";
long charsRead = 0;
FILE* pFile = 0;
pFile = fopen(stockPrices, "r");
if (pFile) {
while (fgets(prices, _NUMB_OF_STOCKS, pFile) != NULL) {
charsRead = strlen(prices);
printf("Closing price: %s\n", prices);
}
}else {
printf("Error opening %s file for read\n", stockPrices);
}
if(pFile) fclose(pFile);
}
double getMinPrice(double* pPrices, int size) {
}
void test() {
banner();
readPrices();
// getMinPrice();
// getMaxPrice();
// profitableTrades();
// save();
// print();
}
int main() {
test();
return 0;
}
Answer:
double getMinPrice(double* pPrices, int size) //function to
return min price
{
double min;
pPrices=&size[0];
min=*pPrices; //variable
min stores the first element of the array
for(i=0;i<5;i++,pPrices++)
{
if(*pPrices<min)
{
min=*pPrices;
}
}
return min;
//returns the min price as a double
}
double getMaxPrice(double* pPrices, int
size) //function to return max price
{
double max;
pPrices=&size[0];
max=*pPrices; //variable max stores the
first element of the array
for(i=0;i<5;i++,pPrices++)
{
if(*pPrices>max)
{
max=*pPrices;
}
}
return max;
//returns the max price as a double
}
Pease help ASAP C programming course. Cannot use global variables. This is the assignment: In this...
C programming course. Cannot use global variables. This is the assignment: In this project you will calculate the maximum profit you could have made by trading a single stock over a period of one month. You will assume that you bought rounded stock units (usually in hundreds, or tens) worth between $3000 and $5000 at the best possible“closing” price during the period and sold it at the best possible “closing” price. You will assume that you are permitted to buy...
PROGRAMING IN C. PLEASE HELP FIX MY CODE TO FIT THE FOLLOWING CRITERIA: 1.)Read your stocks from your mystocks.txt file. You can use this information for the simulator. 2.)The stock price simulator will return the current price of the stock. The current prices is the prices of the requested ticker + a random number. 3.)We will assume that the stock price remains constant after the price check till your trade gets executed. Therefore, a buy or a sell order placed...
C Programming // Compile with: clang radio.c -o radio // Run with: ./radio #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size; song++){ // Allocate memory for each individual character string database[song] =...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...
The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also please explain why the seg fault is happening. Thank you #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size;...
Please help with this coding 1.You need to dynamically allocate memory to read into a number of elements. At first, you need to determine how many numbers (here, ‘n’) to be read. Next, you need to dynamically allocate memory for ‘n’ integers. As you see,‘x’ is an integer pointer which needs to dynamically allocate memory to read ‘n’integers into it fromthekeyboard. 2 Read nintegers into the allocated block using scanf. 3. Complete the printArrayfunction to display ‘n’ integers. void printArray(int...
//C programing help #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #define SIZE 5 int main() { double gradesWithBonus[SIZE]; int i; for (i = 0; i < SIZE; i++) { printf("Please enter your grade: "); //getting grade scanf("%lf", &gradesWithBonus[i]); printf("\n"); } for (i = 0; i < SIZE; i++) { //adding 5 to entered grade double bonous; bonous = gradesWithBonus[i] + 5.0; printf("Grade entered at array element...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
Need this in C
The starter code is long, if you know how to do it in other way
please do.
Do the best you can please.
Here's
the starter code:
//
-----------------------------------------------------------------------
// monsterdb.c
//
-----------------------------------------------------------------------
#include
#include
#include
//
-----------------------------------------------------------------------
// Some defines
#define NAME_MAX 64
#define BUFFER_MAX 256
//
-----------------------------------------------------------------------
// Structs
typedef struct
{
char name[NAME_MAX];
int hp;
int attackPower;
int armor;
} Character;
typedef struct
{
int size;
Character *list;
} CharacterContainer;
//
-----------------------------------------------------------------------
//...
C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...