Hey guys,
I am completely lost after writing a tiny portion of the code.
There are the specifics:
The user starts with a bank of $10.00
It costs a dollar to play
A correct guess pays $2.00
The while loop is used for the game loop. It should ask if the user wants to play.
The while loop will check for a value of 'Y' or 'N'. You should also allow for lower case letters to be input.
You MUST prime the while loop by asking if the user wants to play before the loop starts.
You should output the bank before asking for a guess.
You should use the random number generator to generate a value of 0 and 1. A value of 0 = Heads (H), and a value of 1 = Tails (T);
Your program will take in a value of 'h' (Heads) or 't' (Tails) as the input value of the guess.
To determine if the user wins you will compare the users guess to the value generated by the random number generator.
Note that a conversion will have to take place to convert the number generated to a character.
The game should continue until the user indicates they do not want to play anymore. Your code should ask if the user wants to play again.
When the while loop ends you should thank the user for playing and output the bank.
A do-while loop is not a while loop. You MUST use a while loop.
The output looks something like this:
Welcome to the coin flip game. It costs a dollar to play.
If you guess correctly, you will win $2.00.
Do you want to play (y/n)?
y
Your bank is $10
Enter heads or tails (h/t)
h
Winner, the coin flip came up heads
Would you like to play again (y/n)?
y
Your bank is $11
Enter heads or tails (h/t)
t
Winner, the coin flip came up tails
Would you like to play again (y/n)?
y
Your bank is $12
Enter heads or tails (h/t)
t
Sorry, you lose. The coin flip came up heads
Would you like to play again (y/n)?
n
Thanks for playing, your bank is $11
Please come again.
I would appreciate any help to this problem. I am pretty new to the language and I think that my class is moving ahead really fast for me to handle as a beginner.
Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
char ser;
cout << "Welcome to the coin flip game. It costs a dollar to play." << endl;
cout << "If you guess correctly, you will win $2.00" << endl;
cout << "Do you want to play (y/n)?" << endl;
cin >> ser;
int guess;
int answer;
int bank = 10, h = 0, t = 1;
while ()
{
cout << "Your bank is $10" << endl;
cout << "Enter heads or tails (h/t)" << endl;
cin >> guess;
}
return 0;
}
|