I am trying to get my homework assignment to work for class, but I cant seem to get it. Heres the assignment.
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; }
What is the purpose of roll ? Look carefully at these lines and make sure they are what you want. See red highlight.
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;
}