Q:

IF statement and rand() function not working properly. (C++)

Everytime i run this code, the IF statement does not strictly follow the condition given. it also displays "noway" sometimes when i generate a 1 or 2 and sometimes does not display it when i generate a 6 for example. I have no idea what's going on.
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    srand(time(0)) ;

    for(int x = 1; x <2; x++)
    {
        cout << (rand()%6) << endl ;
    }

    if((rand()%6) >= 3)
    {
        cout << " nowaay " ;
    }
}

A:

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";
}

