mercredi 2 mai 2018

c++ rand() only generating 8 between 1-10

I'm trying to generate a random number between 1-10 to then have my switch statement to output a random day of the week, but I can't get it to output any other number except for 8.

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int a = rand() % 10 + 1;
    cout << a << endl;
    if (a != 4)
    { cout << endl << "a is less than 4" << endl;}
    else
    { cout << endl << "a is greater than or equal to 4";}


    return 0;
}




Aucun commentaire:

Enregistrer un commentaire