Roll a die game

If the user roll a 6, I want it to say this "Password to the secret room is"

1
2
3
4
5
6
7
 {
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int randomNumber = rand(); //generate random number
int die = (randomNumber % 6) + 1; // get a number between 1 and 6
cout << "You rolled a " << die << endl;
return 0;
}
closed account (oGwfSL3A)
You mean something like this?:
1
2
3
4
5
6
7
8
9
10
11
 {
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int randomNumber = rand(); //generate random number
int die = (randomNumber % 6) + 1; // get a number between 1 and 6
cout << "You rolled a " << die << endl;
if (die == 6)
{
cout << "Password to the secret room is";
}
return 0;
}

or
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 {
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int randomNumber = rand(); //generate random number
int die = (randomNumber % 6) + 1; // get a number between 1 and 6
if (die == 6)
{
cout << "Password to the secret room is";
}
else
{
cout << "You rolled a " << die << endl;
}
return 0;
}
Last edited on
I knew it had to be if and else statements. Thank You.
closed account (oGwfSL3A)
No problem, glad I could help!
I need to out beat my professor star pupil. Thank you.
Topic archived. No new replies allowed.