dimanche 17 décembre 2017

Issues with a random number generator upon pushing a button and telling if number is even or odd

The issue is that I push the button, the console gives me a number. I push the button again, and THEN it tells me if its even or odd, and immediately spits out yet another random number. I want the random number and even/odd to happen within the same time of pressing the button.

if(value==0){   //If button is pushed
 int v1;
 v1 = (rand()%15);
 printf ("Random number: %d\n", v1);    //print random number
 if(v1 % 2 == 0){   //if number is perfectly divided by 2
         printf("%d is even.",v1);      // print the number is even
 }
     else{
         printf("%d is odd.",v1);       //print the number is odd
     }

}

Aucun commentaire:

Enregistrer un commentaire