Hey guys, I need to make a program that lists out an average, highest and lowest stock price over a one month period. I'm focusing on the average first but it's already giving me problems.
http://omg.wthax.org/error_4.png
Here's what I have so far.
# include <iostream>
using namespace std;
int main()
{
float stock[32];
//Ask for the stock prices.
cout << "List your stock prices during a one month period." << endl;
int day = 0;
int month = 31;
while (day < month)
{
cout << "What was the stock price for day "<< ++day << "?" <<
endl;
cin >> stock[32];
}
//Calculate average stock price
float average;
average = (stock[0]+stock[1]+stock[2]+stock[3]+stock[4]+stock[5]+
stock[6]+stock[7]+stock[8]+stock[9]+stock[10]+stock[11]+
stock[12]+stock[13]+stock[14]+stock[15]+stock[16]+stock[17]+
stock[18]+stock[19]+stock[20]+stock[21]+stock[22]+stock[23]+
stock[24]+stock[25]+stock[26]+stock[27]+stock[28]+stock[29]+
stock[30]+stock[31]+stock[32])/31;
cout << "Your average stock price over the month is " << average <<
endl;
}
Yeah... really confused why this is happening. I would also like to know how to sort the numbers in array from highest to lowest and vice versa. I'm guessing I need to compare those values somehow in a while but I have no idea how to go about doing.