I need to make a craps game for my programming class but there are a few issues when I try to execute it.
1. How do I calculate the win percentage?
2. When I ask if the user wants to play another game and I say no, it's supposed to show the total wins and losses as well as the win percentage. But it comes up as an infinite loop that keeps going until I terminate the program. How do I fix this?
3. When I display the score, it's incorrect.
4. When I ask if the user wants to play craps and I say yes, for the first roll it rolls twice. I just need it to roll once and then for the user to press enter for it to roll again.
If anyone can help me with these issues that would be great!
> How do I calculate the win percentage? number_of_wins * 100. / times_played;
or perhaps number_of_wins * 100. / (number_of_wins + number_of_loses);
> When I ask if the user wants to play another game and I say no
first, you can't say `no'. either `y' or `n', just one character, because you used a char to hold the answer.
second, your logic is all over the place. limit your input/output to main()
you have three places when you ask the user if they want to play:
- the first time in main()
- when they win
- when they lose (¿why should this be different?)
also you use a loop but then launch the function through recursion
and once you enter a valid answer, you never change the variable anymore.
really, scratch all that, limit your input/output to main()
> When I display the score, it's incorrect.
¿incorrect how? be more descriptive
¿what's the result you are seeing? ¿what are you expecting?
the error is probably because of the recursive calls.
> When I ask if the user wants to play craps and I say yes, for the first roll it rolls twice.
¿you pressed <Return> after 'y' right? cin >> play; cin.ignore();