forked from CPRO-Session1/Assignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandnum.c
More file actions
30 lines (26 loc) · 641 Bytes
/
Copy pathrandnum.c
File metadata and controls
30 lines (26 loc) · 641 Bytes
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
/* Christopher Liu - Generates a random number, mods to 10, adds one. Then continually takes guesses from user, checks to see if too high or low, until they get it right. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int user_guess;
srand(time(0));
int rand_num = rand();
rand_num %= 10;
++rand_num;
while (user_guess != rand_num)
{
printf("Enter your guess: ");
scanf("%d", &user_guess);
if (user_guess < rand_num)
printf("Your guess is too low.\n");
else if (user_guess > rand_num)
printf("Your guess is too high.\n");
else
{
printf("Your guess is correct!");
}
}
return 0;
}