< Previous | Contents | Next >
Introducing the Score Rater 2.0
The Score Rater 2.0 program also rates a score, which the user enters. But this time, the program uses an if statement with an else clause. Figures 2.2 and 2.3 show the two different messages that the program can display based on the score the user enters.
Figure 2.2
If the user enters a score that’s 1000 or more, he is congratulated.
You can download the code for this program from the Course Technology website (www.courseptr.com/downloads). The program is in the Chapter 2 folder; the filename is score_rater2.cpp.
// Score Rater 2.0
// Demonstrates an else clause
#include <iostream> using namespace std;
int main()
{
int score;
cout << "Enter your score: ";
cin >> score;
if (score >= 1000)
{
}
else
{
}
cout << "You scored 1000 or more. Impressive!\n";
cout << "You scored less than 1000.\n";
}
Figure 2.3
If the user enters a score that’s less than 1000, there’s no celebration.