-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab3Part2.c
40 lines (37 loc) · 982 Bytes
/
Lab3Part2.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
/*
* File: main.c
* Author: weiliche
*
* Created on October 1, 2015, 10:39 AM
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv) {
int seed, inputNumber, pickedNumber;
printf("Enter seed: ");
scanf("%d", &seed);
srand(seed);
printf("Guess a number from 1 to 7 (<=0 to quit): ");
scanf("%d", &inputNumber);
while (inputNumber >= 1)//start the loop
{
if (inputNumber > 7)
printf("Number too high, guess again!\n");
else
{
pickedNumber=rand()%7+1;//random number picked between 1 and 7
printf("Number picked: %d\n", pickedNumber);
if (inputNumber == pickedNumber)
printf("Good guess!\n");
else
printf("Sorry, try again!\n");
}
printf("Guess a number from 1 to 7 (<=0 to quit): ");
scanf("%d", &inputNumber);
}
printf("Goodbye");
return (EXIT_SUCCESS);
}