Using the if selection statement, to write a Hot/Cold game, a game that will ask
ID: 3528859 • Letter: U
Question
Using the if selection statement, to write a Hot/Cold game, a game that will ask the user to make a guess then will reply either "You got it right!!" or : "Too cold, Cold, Worm, Hot, Very hot". Say if the correct answer is 33 and the user answer a number that is +1 (34) or -1 (32) the program will say Too Hot, if the user guess a number that is 2 to 5 away (28 to 31 or 35 to 38) will give Hot, if the user guess a number that is 6 to 10 away he gets warm, if the guess is 11-15 away he gets cold, if the guess is greater than 15 away gets too cold. Notice that 33 is just an example to illustrate the program functionality, write the program so it is easy to change that number and get a new game every time with making the minimum number of changes. Hint: You must hide the number in a constant variable call it hide for example, and is set by the programmer not the user, then every time the programmer needs to change the game will only change the value of one variable in the program and compile again.Explanation / Answer
main()
{
int a,b=33;
printf("enter a number");
scanf("%d",&a);
if(a==b)
printf("you got it right");
else if(a==b-1||a==b+1)
printf("too hot");
else if(a+1<b+5||a-1>b-5)
printf("hot");
else if(a+6<b+10||a-6>b-10)
printf("warm");
else(a+11<b+15||a-11>b-15)
printf("cold");
if(a>b+15)
printf("too cold");
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.