rand() is not random at all, it will always produce a specific number when you run your guessing game. Modify your your solution, named the new file guessing2dot0.c. Version 2 of the guessing game will have the following improvements: 1. Add srand(time(NULL)); statement before generating a random number (If you have not done this already) to increase the randomness of rand() 2. User have 5 second to guess the correct number. 3. Before terminating , print out a message to indicate that the time is up. You will need to create a customized handler for SIGALRM, and use signal() system call to catch it. A Guessing Game Asking user to guess a number, only stop when the
rand() is not random at all, it will always produce a specific number when you run your guessing game. Modify your your solution, named the new file guessing2dot0.c. Version 2 of the guessing game will have the following improvements:
1. Add srand(time(NULL)); statement before generating a random number (If you have not done this already) to increase the randomness of rand()
2. User have 5 second to guess the correct number.
3. Before terminating , print out a message to indicate that the time is up. You will need to create a customized handler for SIGALRM, and use signal() system call to catch it.
A Guessing Game
Asking user to guess a number, only stop when the
number is guessed correctly.
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int randomnumber;
srand(time(NULL));
randomnumber = rand() % 10;
int guessNo;
printf("Guess a number from 1-10: ");
scanf("%d",&guessNo);
do{
if(guessNo == randomnumber){
break;
}else{
printf("Guess Again= ");
scanf("%d", &guessNo);
}
}while(randomnumber != guessNo);
printf("You got it!");
return 0;
}

Step by step
Solved in 2 steps with 4 images









