Sams Teach Yourself C++ in 21 Days

(singke) #1
14: cin >> YankeesScore;
15:
16: cout << “\n”;
17:
18: if (MetsScore > YankeesScore)
19: cout << “Let’s Go Mets!\n”;
20:
21: if (MetsScore < YankeesScore)
22: {
23: cout << “Go Yankees!\n”;
24: }
25:
26: if (MetsScore == YankeesScore)
27: {
28: cout << “A tie? Naah, can’t be.\n”;
29: cout << “Give me the real score for the Yanks: “;
30: cin >> YankeesScore;
31:
32: if (MetsScore > YankeesScore)
33: cout << “Knew it! Let’s Go Mets!”;
34:
35: if (YankeesScore > MetsScore)
36: cout << “Knew it! Go Yanks!”;
37:
38: if (YankeesScore == MetsScore)
39: cout << “Wow, it really was a tie!”;
40: }
41:
42: cout << “\nThanks for telling me.\n”;
43: return 0;
44: }

Enter the score for the Mets: 10

Enter the score for the Yankees: 10

A tie? Naah, can’t be
Give me the real score for the Yanks: 8
Knew it! Let’s Go Mets!
Thanks for telling me.
This program asks for the user to input scores for two baseball teams; the scores
are stored in integer variables,MetsScoreand YankeesScore. The variables are
compared in the ifstatement on lines 18, 21, and 26.
If one score is higher than the other, an informational message is printed. If the scores
are equal, the block of code that begins on line 27 and ends on line 40 is entered. The
second score is requested again, and then the scores are compared again.

OUTPUT


82 Day 4


LISTING4.4 continued

ANALYSIS
Free download pdf