I have this program to write thats a guessing game. the user specifies the amount of rounds and only 5 attempts per round is allowed a round is over when the user guesses correctly or the number of attempts are up. A Message is displayed to inform the user whether he/she is cold, hot or warm based on a certain criteria:
#include <stdio.h>
#include <stdlib.h>
/*Funtion Prototypes*/
int genRandom(void);
int main(void)
{
/*Declare variables*/
int rounds;
int ranNum;
int guess;
int attempts=5;
int score;
printf("\nEnter the desired number of rounds\n");
scanf("%d",&rounds);
do{
ranNum=genRandom();/*Call random function*/
printf("Your rannum is %d\n", ranNum);
do{
printf("Guess the value of the random number\n");
scanf("%d",&guess);
if(guess>100)
{
printf("Invalid!!!Your source base must be less than 100\n\n");
}
attempts=attempts-1;
if (ranNum==guess)
{
printf("Congratulations,You are correct!\n");
}
if ((ranNum-guess) >40)
{
printf("You are Cold\a\n");
}
else if (10<=(ranNum-guess)<=40)
{
printf("You are Warm\a\n");
}
else if ((ranNum-guess) < 10)
{
printf("You are Hot!\a\n");
}
}while(attempts!=0);
}while(rounds!=0);
score=5*(5-attempts);
printf("Your score is %d\n", score);
}/* end of main*/
int genRandom(void)
{
return rand()%100;
}
1. How do I work with only absolute or positive values for my criteria (say number is less than guess)
2. I want to break out of the loop when the guess is correct or when the attempts are up.