vendredi 3 avril 2020

I can't seem to pick a random number within the range set

I have this:

cin >> command;
if (command[0] == 'R' or command[0] == 'r') {
    if (command[1] == 'o' and command[3] == 'l' and command[2] == 'l') {
        if (command[4] == '\0') {
            cout << rand()+ 1 << endl;
        } 
        else if (command[5] == '\0')
        {
            NumberName = command[4];
            cout << (rand()%NumberName)+ 1 << endl;
        }
        else if (command[6] == '\0')
        {
            NumberName = command[4] + command[5];
            cout << (rand()%(NumberName))+ 1 << endl;
        }
    }
}

and running it produces random numbers outside the range. command is a array with a limit of 30. NumberName is just a normal int.

I enter this in the console: roll10 and it returned 90 then 34 then 51 you get the idea




Aucun commentaire:

Enregistrer un commentaire