Hello! I wrote a program that when a user inputs all their test scores, it outputs the sum, the highest score, the lowest score, and how many scores were inputted. However, I do not know how to output how many scores were inputted. I was told that I'd need to use count to accomplish this, but I have no idea how, where, or when to use it. Any help would be greatly appreciated, thanks!!!
#include <iostream>
usingnamespace std;
int main()
{
double score, hi, lo;
double sum = 0;
cout << "Please enter your test scores and write a negative number when you're finished:\n";
// Loop if input is between 0 and 100
while(score > 0)
{
cin >> score;
// Finding lowest score
if(score < lo)
lo = score;
// Finding highest score
elseif (score > hi)
hi = score;
sum = sum + score;
score++;
}
// Output showing how many scores (TO BE DETERMINED)
// Output showing sum.
cout << "\nYour sum is " << sum << ".\n";
// Output showing highest score
cout << "Your highest score was " << hi << ".\n";
// Output showing lowest score
cout << "Your lowest score was " << lo << ".\n";
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
double score, hi, lo;
double sum = 0;
int scores = 0;
cout << "Please enter your test scores and write a negative number when you're finished:\n";
// Loop if input is between 0 and 100
while(score > 0)
{
cin >> score;
scores++;
// Finding lowest score
if(score < lo)
lo = score;
// Finding highest score
elseif (score > hi)
hi = score;
sum = sum + score;
score++;
}
// Output showing how many scores (TO BE DETERMINED)
// Output showing sum.
cout << "\nYour sum is " << sum << ".\n";
// Output showing total scores that were input.
cout << "\nYour total is " << scores << ".\n";
// Output showing highest score
cout << "Your highest score was " << hi << ".\n";
// Output showing lowest score
cout << "Your lowest score was " << lo << ".\n";
return 0;
}
However, I've encountered a new problem: since the directions to my assignment make me end the loop with a negative number, my program sets that negative number as the lowest value. How do I make the SECOND lowest value = lo?
Also add the line 6: double score, hi, lo = 1000;
But be careful--if the user enters all the numbers higher than 1000 the lowest score will be reported as 1000 which is incorrect.
I would try to think of a way around this.