I'm still struggling with this one im afraid
Heres my revised code..
My (current) problem is that im getting 'syntax error before float' for the line in red.. I've tried changing it around, and i can't get anywhere with it. Thanks to anyone willing to give me a hand (sorry the code is a bit hard to read at times, layout is not one of my strong points).
As always, if im being an idiot feel free to say so...
Code:
#include <stdio.h>
void generatePrices(float *firstEntry, int *numDays, float *startPrice);
float averagePrice(float *firstEntry, 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( float *firstEntry);
averagePrice( int *startDay, int *endDay );
}
return 0;
} //end of main function
/* *************************************************************************************************** */
void generatePrices(float *firstEntry, float *startPrice);
{
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(float *firstEntry, 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 average to main
}