Calculating Average and high/lowest test score

This is a discussion on Calculating Average and high/lowest test score within the C++ Programming forums, part of the General Programming Boards category; Hello, I am getting frustrated because I am currently trying to figure out how to solve this program:
Write a ...

Calculating Average and high/lowest test score

Hello, I am getting frustrated because I am currently trying to figure out how to solve this program:

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.

Hello, I am getting frustrated because I am currently trying to figure out how to solve this problem by writing a program:

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.

So far this is what I have:

Code:

#include <iostream>
int main()
{
using namespace std;
double score, average, highest, lowest;
int counter = -1;
do
{
counter++;
cout << "Please enter a score (enter -1 to stop): ";
cin >> score[counter];
} while (scores[counter] >= 0);
cout << "Highest is ";
cin >> highest;
cout << "Lowest is ";
cin >> lowest;
// I am stuck at this point. Here is what
// I have tried but I don't have a good grasp
// of how to use the necessary language features:
//code that we can help you with
// . . .
return 0;
}

BTW, do you want to ask the user what the highest and lowest are? Suppose the user enters some random value... Instead, you can calculate the max and min of the set without the user's help... how would you do it as a human?

EDIT: And what does score[counter] mean? What is scores? Try to break this program down maybe a line at a time and see if it compiles and behaves as you expect.

I'm pretty new to c++ and this class I am taking is going really fast for me which is why I'm having a hard time with these problems. I have tried to solve it again, and got what is listed below. However, it keeps giving me errors and I still do not understand how to get the highest/lowest scores that the user enters. From the scores that the user entered, I want the program to find out what the highest and lowest are. The score[counter] is the user's input of all the scores.

The code up until the end of the do-while loop makes sense to me. You accept up to 75 scores, where the user can enter any negative number to stop entry.

Now you make a little mistake with your sum. Addition between a double (sum) and an array of doubles (scores) is not defined explicitly. You need to add each number to sum individually. That is, scores[0], scores[1], all the way to scores[counter-1].

Then your cout calls at the end. You seem to want to display the average, but instead you ask the user to give a value for the average. It looks like a slip of the mind. You want this:

Code:

cout << "Average is " << average << endl;

Which is the same as if you did

Code:

cout << "Average is ";
cout << average << endl;

The endl tells the stream to go to a new line and actually print out what you wrote right away.

You also seem to make no effort to find what the highest and lowest are. How would you know? What makes a number the biggest or the smallest? What would your program have to do? I'll do the highest.

std::min, std::max, and std::accumulate would be the fancy C++ way of doing it, but I gather you need to learn the fundamentals of programming itself rather than how to use the C++ standard library.

At the moment we can tell you have a lack of basic understanding of concepts as you're playing the syntax guessing game for a very basic assignment. I'm not prepared to give you enough rope to hang yourself on this one. Make more time to study how to use the language.