0

Here's what Im trying to do...

Write a program that asks the user to guess the next roll of a six sided die. Each guess costs $ 1. If they guess correctly, they get $ 100.00. The player will start out with a $10.00 bank. Each time he (or she) guesses incorrectly you will subtract $1.00 from their bank. Each time they guess correct, you add $100.00 to their bank. Print the total winnings or loss at the end of the game. [Each die toss is simulated using die = (int)(rand() % 6) + 1;]

program should look something like this:

    Your bank is $10.00 
    Please enter your guess for the next roll. It only costs $1.00 to play,  If you are correct I will pay you $100.00:

    6
    Sorry, the dice rolled a 5.
    continue?

    y

    Your bank is $9.00 
    Please enter your guess for the next roll. It only costs $1.00 to play,  If you are correct I will pay you $100.00:

    4
    Winner! the dice rolled a 4.
    continue?
    n
    Thanks for playing your bank is $109.00. Come back real soon

here's the code I have so far, what am I doing wrong?

#include <iostream>
using namespace std;
int main()
{
    int bank = 10;
    int dice = (int)(rand() % 6) + 1;
    int guess;
    char answer;

    cout<< "Welcome to my casino, Your bank is $10.00, Correctly guess what number will roll next.If you guess right you will $100.00 " << endl;
    cout<< "It only cost one dollar to begin " << endl;
    cout<< " Do you want to play Y or N? " <<endl;
    cin>>answer;

    while (answer = 'Y')
    {
        cout<< "Please enter your guess " << endl;
        cin>>guess;
        cout<<endl;
        break;



    if (guess !=dice)
    {

        cout<< "Sorry you are wrong, you have: " << bank-1<< endl;
        cout<< " would you like to play again? " << endl;
        }
    if (guess = dice)
    {
        cout<<"congradulations you have won 100!! you now have " <<bank + 100<<endl;
        cout<< " would you like to play again" << endl;
        cin>> answer;
    }
    }
    cout<<endl;

        return 0;

}

Edited by Dani: Formatting fixed

3
Contributors
13
Replies
14
Views
6 Years
Discussion Span
Last Post by Akill10
0
while (answer = 'Y')//should be ==
{

Why is this here?

while (answer = 'Y')
{
cout<< "Please enter your guess " << endl;
cin>>guess;
cout<<endl;
[B]break;[/B]//why do you have this here?
if (guess = dice){//This is not correct. You need ==

You have no input from the user if the guess != dice.

You are not creating a new random number. Your giving a random value to dice, and using it in your loop. You need to generate a new number each time you guess.

Edited by Akill10: n/a

0

Why is this here?

while (answer = 'Y')
{
cout<< "Please enter your guess " << endl;
cin>>guess;
cout<<endl;
[B]break;[/B]//why do you have this here?
if (guess = dice){//This is not correct. You need ==

You have no input from the user if the guess != dice.

You are not creating a new random number. Your giving a random value to dice, and using it in your loop. You need to generate a new number each time you guess.

How do i set it up??? I'm completely lost?

0

What do you mean set up? Please re-read my above post,I have edited it further.

Edited by Akill10: n/a

0

ok i have edited to follwing code, not sure how to progress from here :

#include <iostream>
using namespace std;
int main()
{
    int bank = 10;
    int dice;
    int guess;
    char answer;

    cout<< "Welcome to my casino, Your bank is $10.00, Correctly guess what number will roll next.If you guess right you will $100.00 " << endl;
    cout<< "It only cost one dollar to begin " << endl;
    cout<< " Do you want to play Y or N? " <<endl;
    cin>>answer;

    while(answer == 'Y')
    {
        cout<< "Please enter your guess " << endl;
        cin>>guess;


    }   
        return 0;

}

Edited by Dani: Formatting fixed

0

i guess a better statement is, i understand how to get to this point, i also understand what the dice code will be but how do i write a statement that says : if answer = dice, you win, and if answer does not you loose 1 dollar play again y/n??

0

Also thank you for taking the time to help me... I suck at this, but i really do appreciate your help!!

0

You had already written code to do this, why have you removed it? If you saw my above post you can see that there were only slight mistakes.

0

Sorry my man, the battery of my laptop is just about gone! Hopefully somebody else is online to help you. Sorry!

0

Insted of char variable use int variable like 2 for continue and 3 to stop it will work try it

0

#include <iostream>
using namespace std;
int main()
{
int bank = 10;
int dice = (int)(rand() % 6) + 1;
int guess;
char answer;

cout<< "Welcome to my casino, Your bank is $10.00, Correctly guess what number will roll next.If you guess right you will $100.00 " << endl;
cout<< "It only cost one dollar to begin " << endl;
cout<< " Do you want to play Y or N? " <<endl;
cin>>answer;

while (answer == 'Y')
{
cout<< "Please enter your guess " << endl;
cin>>guess;
cout<<endl;

if (guess ==dice)
{

cout<< "Sorry you are wrong, you have: " << bank-1<< endl;
cout<< " would you like to play again? " << endl;
}
if (guess != dice)
{
cout<<"congradulations you have won 100!! you now have " <<bank + 100<<endl;
cout<< " would you like to play again" << endl;
cin>> answer;
}
}
cout<<endl;

return 0;

}

0

this above code is what i have now, I can't figure out how to get it to work from here...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.