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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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;
}

Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY