![]() |
| | #1 | |
| Registered User Join Date: Oct 2009
Posts: 3
| 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 me Quote:
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! | |
| jualin is offline | |
| | #2 |
| Guest Join Date: Aug 2001
Posts: 4,923
| >> 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. How can you calculate the ratio if 'numwins' never get's updated? >> I am not allowed to change the parameters of any of the functions, even though I thought about doing that. In that case, make 'numwins' a global variable. Also, I'm assuming 'newmoney' is being modified inside the 'PlayGame' function - correct? |
| Sebastiani is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 3
| Re: My professor does not allow me to use global variables, thank you for the idea. Also newmoney is not being modified inside of the PlayGame function because the function returns the integer "money", and I cannot change the parameter of the function. This is my new improved code which almost works, the only problem is that the percentage is off by one game won. For instance if I won 4 games out of 5 it tells me that I won 60% instead of 80%. Code: int main()
{
/* CONSTANTS */
/* VARIABLES */
int money = 1000,
oldmoney = money;
double numgames =0,
numwins=0;
/*Print an introductory title*/
srand(static_cast<unsigned>(time(NULL)));
PrintHeading(money);
do
{
money = PlayGame(money);
numgames++;
if (money > oldmoney)
{
numwins++;
}
else
{
numwins = numwins;
}
} while ( PlayAgain() && money > 0 );
cout << "You have won " << setprecision(4) << (numwins/numgames) * 100 << "% of the games you played" <<endl;
return (0);
}
|
| jualin is offline | |
| | #4 |
| Registered User Join Date: Oct 2009
Posts: 2
| I lurk here for searching through the forums and ran across your thread. I think I should be able to help you. Is it possible for you to post the code as a whole? You can also contact me through aim: winggundam3451 Just hard to fix everything without being able to load it into VS. Fastest way would be to send me a msg to my gmail. lordtalonhands@gmail.com Hope I can help you out! Feel free to contact me. -Ryan Last edited by ryandamartini; 10-25-2009 at 08:21 PM. |
| ryandamartini is offline | |
| | #5 | |
| Registered User Join Date: Oct 2009
Posts: 3
| Quote:
| |
| jualin is offline | |
| | #6 |
| Registered User Join Date: Oct 2009
Posts: 2
| cool. You wouldnt happen to go to FSU would you ? My friend has this exact program to work on for his class. Would it be possible for him to meet up with you ? Ive tried to help him from aim, but it has not worked too well. |
| ryandamartini is offline | |
![]() |
| Tags |
| basic, functions, game, hilo |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ace high and low in card game | ninety3gd | C Programming | 3 | 05-10-2009 08:16 PM |
| C/C++, low or high level? | Sentral | General Discussions | 4 | 01-23-2007 11:43 PM |
| what is the significance of low order and high order bits | Shadow12345 | Windows Programming | 1 | 11-16-2002 11:46 AM |
| high or low ! | Beginner2002 | C Programming | 3 | 07-29-2002 01:24 PM |
| low value, high value and increment | Unregistered | C Programming | 2 | 11-25-2001 09:01 AM |