The value output by your first rand()
call:
cout << (rand()%6) << endl ;
is not the same as the value tested in your second call:
if((rand()%6) <= 3) {
You cannot infer the later from the former. To get a grasp of it, replace your if
test with:
const int alea = rand() % 6;
std::cout << "alea = " << alea << "\n";
if (alea <= 3) {
std::cout << "way\n";
}
1
solved IF statement and rand() function not working properly. (C++)