Objective-C Create an app for a one player guessing game. The program chooses an
ID: 650358 • Letter: O
Question
Objective-CCreate an app for a one player guessing game. The program chooses an integer at random between 1 and 100, and the player enters each guess within a text field. Tell the player whether the guess is higher or lower than the secret number. Allow the player to continue until he or she guesses the number. Objective-C
Create an app for a one player guessing game. The program chooses an integer at random between 1 and 100, and the player enters each guess within a text field. Tell the player whether the guess is higher or lower than the secret number. Allow the player to continue until he or she guesses the number.
Create an app for a one player guessing game. The program chooses an integer at random between 1 and 100, and the player enters each guess within a text field. Tell the player whether the guess is higher or lower than the secret number. Allow the player to continue until he or she guesses the number.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int random_value;
srand(time(NULL));
int guess;
char ans = 'y';
while(ans=='y' || ans=='Y')
{
random_value = rand()%100+1;
while(true)
{
printf(" Enter your guess :");
scanf("%d",&guess);
if(guess>random_value)
printf(" your guess %d is higher than secret number ",guess);
if(guess<random_value)
printf(" your guess %d is lower than secret number ",guess);
if(guess==random_value)
{
printf(" you got the secret number %d ",guess);
scanf("%c",&ans);
break;
}
}
printf(" do you want to play again (enter y or n)");
scanf("%c",&ans);
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.