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 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,...
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...
For this assignment you will develop pseudocode and write a C++ program for a simple calculator....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below. PSEUDOCODE FILE NAME: Calculator.txt C++ SOURCE CODE FILE NAME : Calculator.cpp DESCRIPTION: Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt...
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses...
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The script displays the prompt Guess a number between 1 and 1000 next to a text field. The player types a first guess into the text field and clicks a button to submit the guess to the script. If the player's guess is incorrect, your program should display...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
C program and pseudocode for this problem. A parking garage charges a $2.00 minimum fee to...
C program and pseudocode for this problem. A parking garage charges a $2.00 minimum fee to park for up to three hours and additional $0.50 per hour over three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT