Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a c program called random.c that does a guessing play. program will choose

ID: 3630054 • Letter: W

Question

write a c program called random.c that does a guessing play. program will choose a number btw 1 and 100, and you have to choose guessing what the number is. The program will let you know how you’re doing with that guess you just picked. When you choose a right guess, the program will let you how many guesses it took.
How close Message
> 50 ice cold
= 50 cold
= 30 cool
= 20 warm
= 10 hot
= 2 boiling hot


Random Numbers

To produce a random int between 1 and 100, do this:
/* These go before main() */
#include <stdlib.h>
#include <time.h>

/* These go at the beginning of main() */
srand(time(NULL)); // Seed the random number generator
int goal = rand() % 100 + 1; // goal will be 1-100, inclusive

this is just a Sample Run but the output in your c program must come out the SAME

In this example, the prompt is “%”. Text like this is what the user types in while running the program. Your output should match exactly.
% c99 guesser.c
% ./a.out
I have a number, 1-100.
What's your guess? 103
103 is not 1-100.
What's your guess? 3
3 is ice cold.
What's your guess? 20
20 is cold.
What's your guess? 90
90 is cool.
What's your guess? 75
75 is hot.
What's your guess? 45
45 is cool.
What's your guess? 50
50 is warm.
What's your guess? 70
70 is boiling hot.
What's your guess? 67
67 is boiling hot.
What's your guess? 78
78 is hot.
What's your guess? 68
68 is right in 11 guesses.

Explanation / Answer

please rate - thanks

#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int main()
{int randomdigit,number,count=0,diff;
srand(time(0));
randomdigit=(rand()%100)+1;
printf("Guess a number between 1 and 100 ");
do
     {count++;
      printf("What's your guess: ");
         scanf("%d",&number);
      if(number<1||number>100)
          printf("%d is not 1-100. ",number);         
       else if(number==randomdigit)
        printf("%d is right in %d guesses. ",number,count);
      else
         {diff=abs(randomdigit-number);
          if(diff>50)
             printf("%d is ice cold. ",number);
          else if (diff>30)
             printf("%d is cold. ",number);
          else if (diff>20)
             printf("%d is cool. ",number);  
          else if (diff>10)
             printf("%d is warm. ",number);
          else if (diff>2)
             printf("%d is hot. ",number);
           else
             printf("%d is boiling hot. ",number);      
         }
   
    }while(randomdigit !=number);
getch();
return 0;
}