forked from anish2210/hacktober2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
38 lines (32 loc) · 855 Bytes
/
game.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
//simple game in c
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int number,nguess,guess;
srand(time(0));
number=rand()%100+1;
printf("\n WELCOME TO THE NUMBER GUESSING GAME");
printf("\n Lets start the game");
nguess=1;
do
{
printf("\n Guess an number between 1 to 100:");
scanf("%d",&guess);
if (guess<number)
{
printf("\n You have guessed the number lower ..Try again");
}
else if (guess>number)
{
printf("\n You have guessed the number higher ..Try again");
}
else{
printf("\n Congratulations..You have guessed the right number in %d attempts",nguess);
}
nguess++;
} while (guess!=number);
printf("\n Thanks for playing the game");
return 0;
}