I am trying to get my homework assignment to work for class, but I cant seem to get it. Heres the assignment.
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;]
Your 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
Seems not to bad doesnt it? Well I have been working for a while and it still isnt working for me. I enter lets say a 4 it will tell me Sorry, the dice rolled a 5. I need a little help if anyone can please. I am not looking for you to complete my assignment, but take a look and give some advice for a beginner.
Thanks :)
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int die;
int money=10;
int num;
char roll;
{
cout<<"Your bank is $" <<money<<endl;
cout<<"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:" <<endl;
cin>>num;
cin.get(roll);
die=(int)(rand()%6)+1;
if (num==die)
{
cout<<"Winner! The dice rolled a" <<num<<endl;
money += 100;
}
else if (num < die)
{
cout<<"Sorry the dice rolled a "<<num<<endl;
money -= 1;
}
}
return 0;
}