Use C to write this program Write a program that reads a magic number. Then star
ID: 648694 • Letter: U
Question
Use C to write this program
Write a program that reads a magic number. Then start reading numbers, one-by-one. After each value, offer advice (higher or lower) to the player on how to win the game. If the magic number is entered, the player wins the game! If the player enters 7 numbers without entering the magic number, the player loses the game. Before the seventh number, spit out the words "Last Try!".
Shown below is a sample program dialogue to help you build your program.
Gimme the magic number: 20
Gimme a starting number: 50
Lower
Next: 40
Lower
Next: 1
Higher
Next: 30
Lower
Next: 20
You Won The Game!
Explanation / Answer
#include<stdio.h>
int main()
{
int a,b;
printf(" enter the magic number : ");
scanf("%d",&a);
printf(" enter the starting number :");
scanf("%d",&b);
int i;
for(i=0;i<7;i++)
{
if(i==5)
printf(" last try");
if(b==a)
{
printf(" success!!! ");
i=i+10;
break;
}
else if (b>a )
printf(" lower!");
else if(b<a)
printf(" higher!");
printf (" next :");
scanf("%d",&b);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.