were winding down the semester and just running through some simple (i think) arrays. the description of the assignment is:
Write a program that prompts the user for test scores (doubles). The user enters -1 to stop the entry. After all of the test scores have been entered, calculate the average, the highest and the lowest test score. Use the code below as a template. Make sure you respond appropriately when no test scores are entered.
the code that we were provided is:
what i have so far, which i cant get working is:
using namespace std;
int counter = -1;
cout << "Please enter a score (enter -1 to stop): ";
cin >> scores[counter];
} while (scores[counter] >= 0);
// CALCULATE AND DISPLAY THE AVERAGE
// THE HIGHEST AND LOWEST TEST SCORE
// BELOW HERE -- DO NOT MODIFY THE REST OF
// PROGRAM EXCEPT TO PUT YOUR NAME ETC.
// AT THE TOP.
the program compiles fine, and runs ok until i type in -1. once i do that, the error message i get says something along the lines of 'memory could not be "read."'
double total = 0, average = 0, min = 101, max = 0;
for (int x = 0; x >= 0; x++)
total += scores[x];
average = total/counter;
if (scores[counter] > max)
if (scores[counter] < min)
cout << total << average << min << max;
im not even sure if i am using this for loop correctly or not. i thought that was the right way to calculate the average, but im not too positive on the min/max ones.
thanks for any help fellas.