Question

In: Computer Science

C Program and pseudocode for this problem. Write a C program that plays the game of...

C Program and pseudocode for this problem.

Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or "Too Low" to help the player "zero in" on the correct number.

Solutions

Expert Solution

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main() {

srand(time(0));

int num=(rand()%1000)+1;// To generate numbers in the range of 1 to 1000.

int guess;

scanf("%d",&guess);//taking input guess from the user

//printf("%d\n",num); //you can uncomment this to check the random number

//until the guess is incorrect it will take input from the user

while(num!=guess)

{

if(num>guess)//if the guess is lower than the number it will output Too Low

{

printf("Too Low\n");

}

else//if the guess is higher than the number it will output Too High

{

printf("Too High\n");

}

scanf("%d",&guess);

}

printf("zero in");//it will output zero in when user guesses the number right

return 0;

}

Pseudocode code

Declare num

store random number in num

Declare guess

Take input from user and store it in guess

Run a loop until the guess is equal to num

if guess is higher than num then

print "Too High"

else

print " Too low"

again take input from user and check the conditions

if guess is equal to num then

Print "Zero in"


Related Solutions

For this problem, you will write a program in which the computer plays a dice game...
For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment. PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution Rules: The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Write a program that plays an addition game with the user (imagine the user is a...
Write a program that plays an addition game with the user (imagine the user is a 5th grade student). First ask the user how many addition problems they want to attempt. Next, generate two random integers in the range between 10 and 50 inclusive. You must use the Math.random( ) method call.   Prompt the user to enter the sum of these two integers. The program then reports "Correct" or "Incorrect" depending upon the user's "answer".  If the answer was incorrect, show...
Write a program in Matlab where the program plays a hot and cold game. The user...
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
Using Python, Assignment Write a program that plays a game of craps. The program should allow...
Using Python, Assignment Write a program that plays a game of craps. The program should allow the player to make a wager before each “turn”. Before each turn, allow the user to either place a bet or exit the game. After each turn display the player’s current balance. Specifics Each player will start with $500.00. Initially, and after each turn give the user the option of betting or leaving the program. Implement this any way you wish, but make it...
Write the Pseudocode for the following programming problem. Write a program that will calculate a tip...
Write the Pseudocode for the following programming problem. Write a program that will calculate a tip based on the meal price and a 6% tax on a meal price. The user will enter the meal price and the program will calculate tip, tax, and the total. The total is the meal price plus the tip plus the tax. Your program will then display the values of tip, tax, and total. The tip amounts based on the mean price are as...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
1. Write a program that plays a simple dice game between the computer and the user....
1. Write a program that plays a simple dice game between the computer and the user. When the program runs, it asks the user to input an even number in the interval [2..12], the number of plays. Display a prompt and read the input into a variable called ‘plays’ using input validation. Your code must ensure that the input always ends up being valid, i.e. even and in [2..12]. 2. A loop then repeats for ‘plays’ iterations. Do the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT