Write a complete C++ program that reads in a list of scores until the user enters a negative number. It will add all the given scores up and subtract the biggest and smallest scores to get a true score total.
I am honestly so lost on the part that it requires you to store multiple inputs inside possible one variable. I know that in C++ you can only have one thing stored into one variable.
Note: please do not use array or vector. And please write it in pseudo code if possible(I want to understand whats going on and write the final codes myself)
Second, replace your line 16 by total+=score; if you want to get the sum of all your scores.
Third, to keep in memory your smallest and biggest scores, int maxS and minS. On the first iteration, give them the value of the score.
On the other iterations, if score<minS, then minS=score (and do the opposit for maxS).
After all this, if the input is :
2 5 1 4 6 3
You should obtain :
total=21
minS=1
maxS=6
It runs partially, the program does not reject the max and min for the variable, so it only add up all the numbers
#include <iostream>
using namespace std;
int main()
{
int score;
int total, TrueTotal, Max, Min;
total = 0;
TrueTotal = 0;
for (int counter = 0; score > -1; counter++)
{
cout << "Please enter non-negative score:";
cin >> score;
if (score < 0)
{
break;
}
Max = score;
if (score > Max)
{
Max = score;
}
Min = score;
if (score < Min)
{
Min = score;
}
total +=score;
TrueTotal = total - (Max + Min);
}
cout << "true total score is: " << total << endl;
return 0;
}
EDIT: in case of confusion, this is all referring to the initial post without edit or subsequent posts!!!
You are currently (nearly correctly) keeping a running tally of the total. You forgot to initialise it (to 0), however.
Also keep a running tally of the minimum and maximum values entered. You can subtract them from the total at the end. @Zaap's explanation is fine for this and he/she got their post in first.
BTW, it's not crucial to the operation of your code - just strange - that:
(1) you are doing tests for continuation both as the central item in your for-loop statement and as a test leading to break;
(2) you are incrementing a counter that you don't use and, indeed, couldn't use outside the for-loop, as its scope is confined to that loop; in anticipation of what your next question might well be I would be inclined to fix this.