-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathGuessNumberGame.c
56 lines (51 loc) · 1.43 KB
/
GuessNumberGame.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int number, guess, numguess ,no;
srand(time(0)); //Number Generator
number = rand() % 100 + 1; //Generates a random number between 1-100
printf("Enter no of Chances in which you can crack this game "); scanf("%d",&no);
printf("Here starts the game\n");
for (numguess=1; guess != number && numguess<no+1; numguess++)
{
printf("Enter your guess\n");
scanf("%d", &guess);
if (guess < number)
{
printf("higher number please\n");
}
else if (guess > number)
{
printf("lower number please\n");
}
else
{
printf("Congratulations! You have cracked this Challenge in %d times!!!\n", numguess);
break;
}
}
if (numguess==no+1 && guess!=number){
printf("You Failed in this challenge,Better Luck next time!!!\n");
}
// do
// {
// printf("Enter your guess\n");
// scanf("%d", &guess);
// if (guess < number)
// {
// printf("higher number please\n");
// }
// else if (guess > number)
// {
// printf("lower number please\n");
// }
// else
// {
// printf("You guessed it right in %d times\n", numguess);
// }
// numguess++;
// } while (guess != number);
return 0;
}