A program stores test scores in two int variables named myScore and expectedScore. Write the C++ code to compare the two scores and then display one of the following messages: “I met my expectations”, “I scored higher than expected”, or “I scored lower than expected”.
Make use of either a While Loop, For Loop or a Do While Loop to allow the program to repeat until a sentinel value or counter is used to break out of the loop
Here is program:
int main()
{
int myScore;
int expectScore;
int score, score1;
bool exit = false;
while (!exit)
{
cin >> score;
cin >> score1;
if (score > score1)
{
cout << "“I met my expectations" << endl;
cout << "Continue?" << endl;
cout << "0) Continue" << endl;
cout << "1) Exit" << endl;
cin >> exit;
}
else
{
cout << "I scored higher than expected" << endl;
cout << "Continue?" << endl;
cout << "0) Continue" << endl;
cout << "1) Exit" << endl;
cin >> exit;
}
}
}
Comments
Leave a comment