Im stuck on this program. I'm trying to add my negative values and count them and get the average. when i print them i get 777. the input file i used had "51 144 5 16 8 0 -2 14 6 -4 173 263 11 9345 -135 777" i know my count should be 3 my sum -141 and my average should be -47.0.
int index = 0; // Note: you do not need this
while(infile >> list)
{
if(list < 0){
count++;
sum = sum + list;
}
elsefor(int index = 0; index<list; index++) // This causes a crash
{
positive_num[index] = list; // Note: you do not need this
index++ // Note: you do not need this
}
infile >> list;
}
thanks that worked however, its not reading in all my negative numbers.. its only reading -3 and -135 somehow its leaving the -4 out. the count is 2 and the sum is -137. do you have any idea what this could be?