PART 1) Add the appropriate Boolean expression to the while. The while loop should exit when a team has scored at least 15 points and is ahead by at least 2. That is, the loop exits when the score is 15 – 8 but not 15 -14. Remember that the Boolean expression should be the opposite of the exit condition. Hint: A good strategy in this case is to write a Boolean expression for the stopping condition and apply the NOT operator, !, to it. (PART 2) Also program should play multiple games, wins match at 5 game wins with a difference of at least two games.
I'm having trouble with the second second part 2. How do i get it to play the multiple games and the winner should win by at least two games? As it stands right now, when it compiles, it only lets me play the game 1 time.
This is what i have so far; (Any help would be appreciated)
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
const int STOPSCORE=15;
int main(int argc, char *argv[])
{
int nyu,GAMESPLAYED,gamecounter,game,game3,g…
usc;
char team;
// either n or u
nyu=10;
usc=10;
GAMESPLAYED=0;
while (GAMESPLAYED < 5)
{
cout <<GAMESPLAYED;
GAMESPLAYED++;
while ((nyu < STOPSCORE && usc < STOPSCORE)
||(nyu < usc +2)&&(usc < nyu+2))
{
cout << "score starts from 5. ";
cout << "Who scored the point? ";
cin >> team;
// increment the appropriate score
switch (team)
{
case 'n':
case 'N': nyu++;
break;
case 'u':
case 'U': usc++;
break;
default: cout <<"invalid entry"<<endl;
cout << "Current Score: nyu: " << nyu
<< " usc: " << usc << endl;
}
// print final score
if (usc > nyu)
cout << "\nBoo, usc: " << usc <<
" nyu: " << nyu;
else
cout << "\nYeah, nyu: " << nyu <<
" usc: " << usc;
cout << "\n\n";
}
}
system("PAUSE");
return EXIT_SUCCESS;
}