#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int score, total;
for (int counter = 0; score > -1; counter++)
{
cout << "Please enter non-negative score:";
cin >> score;
if (score < 0) //this takes a negative number and use it as a break to stop the loop
{
total = score + score;
cout << "true total score is: " << total << endl;
break;
}
}
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int score = 0, total; // need to initialise
for (int counter = 0; score > -1; counter++)
{
cout << "Please enter non-negative score:";
cin >> score;
if (score < 0) //this takes a negative number and use it as a break to stop the loop
break;
total = total + score; // not score + score
}
cout << "true total score is: " << total << endl;
return 0;
}