Is there a way that I could display the smallest and largest numbers that the user inputs without using an array? The user can input as many numbers as they want to until they decide to exit the loop. So if the user decided to input 4 numbers, lets say 4, 16, 3, 21. How would I go about it? This needs to work for however many numbers there are, for example the next person who uses the program could input 10 numbers. So, there is no guessing how many numbers a person inputs. The program itself uses a while loop.
So far the code is:
using namespace std;
int main()
{
float game = 1,
score,
total = 0,
average;
cout << "Enter the score\n";
cout << "Type -1 when you have entered all the scores for each
game.\n\n";
cout << "Enter the score for game " << game << ": ";
cin >> score;
while (score != -1)
{
total = total + score;
game++;
cout << "Enter the score for game " << game << ": ";
cin >> score;
if (score == -1) {
game--;
}
average = total / game;
}
cout << "\nThe total score is " << total << endl;
cout << "\n The average score is " << average << endl;
system("PAUSE");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire