0

Alright I know you dont help on homework, but I have don't so much I just need a little guidance on the ending. I just need to make my number guessing game ask the user if they would like to play again and keep there bank.

The assignment:

http://www.glennstevenson.com/c++online/syllabus/midtermfall2008/midterm.html

Heres my code so far:

```
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
char play;
int guess;
bool done;
int noOfGuesses = 0;
int random;
int c;
double bank, winnings, total;
int check;
void printPayout()
{
cout << "1 guess, win 2.00" << endl;
cout << "2 guesses, win 1.75" << endl;
cout << "3 guesses, win 1.5" << endl;
cout << "4 guesses, win 1.25" << endl;
cout << "5 guesses, win 1.00" << endl;
cout << "6 guesses, .75" << endl;
cout << "7 guesses, win .5" << endl;
cout << "8 guesses, win .25" << endl << endl;
}
int checkGuess(int guess)
{
if (guess > random)
{
check = 1;
}
else if (guess < random)
{
check = -1;
}
else
{
check = 0;
}
return (check);
}
int genRandom()
{
int r;
srand(time(NULL));
r = rand() % 100 + 1;
return r;
}
int game()
{
cout << "Welcome to the guess-o-matic. It only costs a dollar to play. You could double your bet." << endl << endl;
cout << "Do you want to play (y / n)" << endl;
cin >> play;
if (play=='y')
{
bank = 100.00;
winnings = 2.00;
cout << "Great!, your payout will be as follows:" << endl << endl;
printPayout();
cout << "Now guess a number between 1 and 100" << endl;
random = genRandom();
while ((noOfGuesses < 10))
{
cin >> guess;
noOfGuesses++;
c = checkGuess (guess);
if (c == 0)
{
total = bank + winnings;
cout << "Correct, you win " << winnings << ", your bank is now "<< total<< endl;
}
else if (c == -1)
{
cout << "Sorry too low try higher" << endl;
winnings = winnings - .25;
}
else if (c == 1){
cout << "Sorry too high try lower" << endl;
winnings = winnings - .25;
}
}
}
return 0;
}
int main()
{
game();
return 0;
}
```