Question

In: Computer Science

Develop a C program that generates a random number from 1 to 100, then prompt the...

Develop a C program that generates a random number from 1 to 100, then prompt the user to guess the number until it is guessed correctly. Let the user know if the guess is too high, too low, or correct. The program should count the number of times the user guesses and display the number, along with their rank, after the number is guessed correctly.

Rank the user as follows:

  • Super Guesser: 1 to 4 guesses
  • Excellent Guesser: 5 to 6 guesses
  • Good Guesser: 7 to 10 guesses
  • Novice Guesser: More than 10 guesses

The program must include a while loop, if statements, and the following user-defined functions:

  • int getRandomNumber();
  • int check4Win(int, int);
  • void printResults(int);

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>

int getRandomNumber();
int check4Win(int, int);
void printResults(int);

int main(){
   int random,guess, counter = 0, result;
   random = getRandomNumber();
   while(1){
       scanf("%d",&guess);
       counter++;
       result = check4Win(random, guess);
       if(result){
           printf("correct");
           printResults(counter);
           break;
       }else{
           if(guess<random)
               printf("too low\n");
           else if(guess>random)
               printf("too high\n");
       }
   }
}

int getRandomNumber(){
     
   return (1 + (rand() % 100));
}

int check4Win(int random, int guess){
   if(random == guess)
       return 1;
   else
       return 0;
}
void printResults(int counter){
   if(counter>=1 && counter<=4)
       printf("\nSuper Guesser");
   else if(counter>=5 && counter<=6)
       printf("\nExcellent Guesser");
   else if(counter>=7 && counter<=10)
       printf("\nGood Guesser");
   else if(counter>10)
   printf("\nNovice Guesser");

}

Screenshot of the program

Output

NOTE: If you want to change something , please let me know through comments; I will surely revert back to you.

Please give a up vote .....
Thank you...


Related Solutions

Create a C++ program that generates a random number from 1 to 100 using the rand()...
Create a C++ program that generates a random number from 1 to 100 using the rand() function. Give the user a total 5 chances to guess the number. Stop the program and indicate the user guessed the correct number and should be applauded. Also, please find out which guess was the closest to the actual number. For example, if the rand() produces 57 and the user guessed 10, 80, 52, 33 and 44 in their respective turns then print out...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
1. make a c++ program that generates a random number 1to 100 using rand(). user gets...
1. make a c++ program that generates a random number 1to 100 using rand(). user gets 5 attempts stop program when they get it right find out which guess was the closest to the actual number and print out that they have to run the difference in miles for example (50-30)=20 miles do not use arrays! very quick upvote for good response
Random Number Guessing Game Write a program in C++ that generates a random number between 1...
Random Number Guessing Game Write a program in C++ that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number....
Write a program that generates a random number between 1 and 100 and asks the user...
Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Your program should also keep a...
Write a program in C++ coding that generates a random number between 1 and 500 and...
Write a program in C++ coding that generates a random number between 1 and 500 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Count the number...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses...
*Write in C* Write a program that generates a random Powerball lottery ticket number . A...
*Write in C* Write a program that generates a random Powerball lottery ticket number . A powerball ticket number consists of 5 integer numbers ( between 1-69) and One power play number( between 1-25).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT