Do you mean to have a prototype that doesn't match the actual call, that again doesn't match the function itself?
Todd
Printable View
Do you mean to have a prototype that doesn't match the actual call, that again doesn't match the function itself?
Todd
i think ive sorted that out... now on to the next one :rolleyes:
i now get told that 'called object is not a function' for the following line from main
This baffles me...Code:else{
generatePrices( firstEntry);
averagePrice( startDay, endDay );
}
return 0;
(genuinely sorry for all the noob questions, i know how irritating it is..)
Similar to before, your function call does not match the function prototype or the function definition itself.
Todd
I cant see what else i can do to them, arrrg i think ill just give it in as it is, at least i gave it a go. Thanks to all who replied
Code:#include <stdio.h>
void generatePrices(float *firstEntry);
float averagePrice(int *startDay, int *endDay);
const int NUMDAYS = 14; //constant used as size of the array
int main()
{
int firstDay, lastDay;
int *startDay = &firstDay; //creates a pointer to firstDay
int *endDay = &lastDay; //creates a pointer to lastDay
float beginPrice, averagePrice;
float *startPrice = &beginPrice;
float prices[NUMDAYS]; //declares array 'prices' of size NUMDAYS
printf ("Welcome to stock tracker\n");
printf ("To begin, please enter the starting price of the share you wish to track: ");
scanf ("%f", &beginPrice); //sarting price entered by user and stored as firstEntry
prices[0] = beginPrice;
float *firstEntry = &prices[0];
printf ("\nPlease enter the day you wish to track from (1 - 14): ");
scanf ("%d", &firstDay);
startDay -= 1;
printf ("\nPlease enter the day you wish to track to (1 - 14): ");
endDay -= 1;
scanf ("%d", &lastDay); //startDay and endDay entered by user and sent to variables
if ( firstDay < 0 || firstDay > NUMDAYS || lastDay < 0 || lastDay > NUMDAYS || lastDay < firstDay || firstDay == lastDay)
{
printf ("\nError: please check that days are within range 1 - 14 and startDay is lower than EndDay");
} //inputs checked for errors
else{
generatePrices( firstEntry);
averagePrice( startDay, endDay);
}
return 0;
} //end of main function
/* *************************************************************************************************** */
void generatePrices(float *firstEntry)
{
int i, j;
j = (int) *firstEntry; //cast firstEntry as an int
for (i=1; i < (NUMDAYS - 1); i++)
{
prices[i] = j - 0.5 + rand() % j + 1.5; //generates prices for share
}
}
/* ***************************************************************************************************** */
float averagePrice(int *startDay, int *endDay)
{
float sum = 0.0, average;
int k;
for (k = startDay; k < endDay; k++ ) {
sum += prices[k];
}
average = (sum / NUMDAYS); //calculate average price
return (average); //return averahe to main
}
This might help you get better fluctations. It's just a simple linear interpolation that chooses a random coefficient.
Keep in mind rand() is a very crappy pseudo random number generator.Code:
float GetRandomFloatRange(float min,float max)
{
float coef = ((float)(rand () % 10000))/10000.0f;
return min + coef *(max-min);
}
See here:
ToddCode:#include <stdio.h>
void generatePrices(float *firstEntry);
float averagePrice(int *startDay, int *endDay);
const int NUMDAYS = 14; //constant used as size of the array
int main()
{
int firstDay, lastDay;
int *startDay = &firstDay; //creates a pointer to firstDay
int *endDay = &lastDay; //creates a pointer to lastDay
float beginPrice, averagePrice; // Is this a variable or a function name? It's BOTH!!
float *startPrice = &beginPrice;
float prices[NUMDAYS]; //declares array 'prices' of size NUMDAYS
printf ("Welcome to stock tracker\n");
printf ("To begin, please enter the starting price of the share you wish to track: ");
scanf ("%f", &beginPrice); //sarting price entered by user and stored as firstEntry
prices[0] = beginPrice; // local to main!!
float *firstEntry = &prices[0];
printf ("\nPlease enter the day you wish to track from (1 - 14): ");
scanf ("%d", &firstDay);
startDay -= 1;
printf ("\nPlease enter the day you wish to track to (1 - 14): ");
endDay -= 1;
scanf ("%d", &lastDay); //startDay and endDay entered by user and sent to variables
if ( firstDay < 0 || firstDay > NUMDAYS || lastDay < 0 || lastDay > NUMDAYS || lastDay < firstDay || firstDay == lastDay)
{
printf ("\nError: please check that days are within range 1 - 14 and startDay is lower than EndDay");
} //inputs checked for errors
else{
generatePrices( firstEntry);
averagePrice( startDay, endDay); // Where is the returned value assigned???
}
return 0;
} //end of main function
/* *************************************************************************************************** */
void generatePrices(float *firstEntry)
{
int i, j;
j = (int) *firstEntry; //cast firstEntry as an int
for (i=1; i < (NUMDAYS - 1); i++)
{
prices[i] = j - 0.5 + rand() % j + 1.5; //generates prices for share
}
}
/* ***************************************************************************************************** */
float averagePrice(int *startDay, int *endDay)
{
float sum = 0.0, average;
int k;
for (k = startDay; k < endDay; k++ ) {
sum += prices[k];
}
average = (sum / NUMDAYS); //calculate average price
return (average); //return averahe to main
}