program

how do i create a program, guessing a number from 1 to 5 then use a switch statement, have the user input a number from 1 to 5 and give a statement for each value, including if they guess the number correct
I won't give the whole solution, but here's part of it.
To randomly pick a number, use rand()

1
2
3
4
5
6
#include <stdlib.h>
int main(int argc, char** argv)
{
   srand(0);  // Initializes the random number generator
   int n = rand();  // Chooses a number between 0 and RAND_MAX
}


On normal computers, RAND_MAX is about 2,100,000.
Next hint, use the % (modulo operator) to limit the random number to the range you want. Google "c++ modulo"
Topic archived. No new replies allowed.