#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i, n, diff;
int x=rand() % 100;
int bMoveHigher = 0;
int bGuessedCorrectly = 0;
printf("Welcome to Guess a Number Game\n");
for(i=1; i<=6; i++)
{
printf("ATTEMPT %d: Enter your number: ", i);
scanf("%d", &n);
if(n==x)
{
printf("Congrats! You have guessed the number correctly\n");
bGuessedCorrectly=1;
break;
}
diff=(int)(fabs(x-n));
if(x>n)
bMoveHigher=1;
if(diff>=50)
{
if(bMoveHigher==0)
printf("Your guess is Very High\n");
else
printf("Your guess is Very Low\n");
}
else if(diff>=30)
{
if(bMoveHigher==0)
printf("Your guess is High\n");
else
printf("Your guess is Low\n");
}
else if(diff>=15)
{
if(bMoveHigher==0)
printf("Your guess is Moderately High\n");
else
printf("Your guess is Moderately Low\n");
}
else
{
if(bMoveHigher==0)
printf("Your guess is Somewhat High\n");
else
printf("Your guess is Somewhat Low\n");
}
}
if(bGuessedCorrectly==0)
{
printf("Unfortunately you did not guess it correctly. The correct number is: %d\n", x);
}
getch();
}
joseph.suanino
0
Newbie Poster
Recommended Answers
Jump to Postcall srand() at the very beginnning of the program, and before the first time rand() is used. Usually srand() is called with the return value from time() so that srand() gets a different number every time it is called. That will prevent rand() from returning the same set of numbers …
All 3 Replies
joseph.suanino
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
David W
131
Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.