The purpose of this project is make use function prototypes to achieve the main objective of the program. This main objective is for the computer to generate a random number between 1 - 100 inclusive. The user is given $1000 to start, then the user will bet some money and needs to guess the right number in a certain number of tries. If the user wins then he wins the bet, if he doesn't then he loses the bet. At the end of the program a function called "playagain" will ask the user if he wants to play again, if the user answers yes, then the money (lost or won) will be utilized for the 2nd game.
The issue that I am having is to be able to tell the user how much percentage of the games he has won at the end of each game.
My T.A. told meThis is part of my code in main. I am not allowed to change the parameters of any of the functions, even though I thought about doing that.that every time the function playgame is called, that counts as one game, so I could keep track of that in the do while in main. He also said that I can determine the wins by comparing the returned by playgame with the money from before you called playgame (with another money variable)...if the new money is more, you know you won.
This code is not working correctly, any ideas?Code:/* MAIN FUNCTION */ int main() { /* VARIABLES */ int money = 1000; // money user starts with double numwins = 0, // number of won games numgames = 0; // number of games played /*Print an introductory title*/ srand(static_cast<unsigned>(time(NULL))); PrintHeading(money); // a void function that prints the heading page do { money = PlayGame(money); // PlayGame should return the money at the end of the game numgames++; // a new game will be counted each time Playgame runs } while ( PlayAgain() && newmoney > 0 ); // user can play again if he says "yes" in PlayAgain and if he has money cout << "You have won " << setprecision(4) << (numwins/numgames) * 100 << "% of the games you played" <<endl;
Thank you!