int num;
int die;
cout << "What number do you think you'll roll? " << endl;
cin >> num;
die=(int)(rand()%6)+1; // So far, so good
if (num<6 && num>0) { // So 0 is a proper guess? But 6 is not?
srand((unsigned)time(0)); // Why are you seeding the random generator
// after you got your random value?
cout << die << endl; // And what good is displaying the die in this case?
}
else if (num==die) { // How can you get here if the above IF is true?
cout << "Congradulations! You predicted correctly. " << endl;
}
else if (num > 6) {
cout << "Number not on die" << endl;
}
system("PAUSE"); // Not a good way to pause the program
return(0);
srand() needs to be called once at the start of the program.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
That's what I can't figure out, suggestions would be appreciated.
Well, if you start by testing if num == die , you now know if the guess is correct or not right away. Why do you need to test for more?
Any comments on my other points?
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944