dice game, iteration with selection

Hello, I am having a problem with the total bank calculating the improper amount of money held.
$1.00 subtracted for each play. $2.00 added for each win.

Ex:
"Sorry, you lost. Your bank is 9. Guess again?"
3
"Sorry, you lost. Your bank is 8. Guess again?"
2
"Sorry, you lost. Your bank is 7. Guess again?"
5
"Congrats. You won! Bank is now 10."
-------------
The bank should read 9 after winning the 4th guess.

I apologize for such obscene noobetry. Any hints would be faaaaaaaaantastic. Thank you.

My code:


#include <iostream>
#include <ctime>

using namespace std;

int main()
{
	char input;
	int guess;
	int ans;
	int banktot = 10.00;

		srand(time(0));

		cout << "Welcome to the dice guess game." << endl;
		cout << "It costs $1.00 to play." << endl;
		cout << "Would you like to continue? (y,n)" << endl; 
		cin >> input;
		
		while (input == 'y')
		{
				cout << "Please enter your guess for the next roll. It only costs $1.00 to play." << endl; 
				cout << "If you are correct. I will pay you $2.00: " << endl;  
				cin >> guess;

				ans = (rand() %6) + 1;

						if (guess == ans) 
						{
							banktot++;
							cout << "Winner! The dice rolled " << ans << ". Your bank is now " << banktot + 2.00 << "." << endl;
						}
						else if (guess != ans) 
						{
							--banktot;
							cout << "Sorry, you lose. " << "The dice rolled " << ans << ". Your bank is now " << banktot - 1.00 << "." << endl; 
						}
				continue;	
		}
		while (input = 'n')
		{
			cout << "Thanks for playing. Your bank is " << banktot << "." << endl;
			break;
		}
	return 0;
}
Last edited on
When they win, you add 1 to their bank then display bank+2...so you are essentially displaying bank+3. Also, the +2 you are displaying isn't actually changing the amount in their bank.
Topic archived. No new replies allowed.