repl.it
@ArjunArunkumar/

something that actually worked-1

C

No description

fork
loading
Files
  • main.c
main.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
	//variable declaration
	int secretNumber ;
	int t;
	int guessesLeft = 5;
	int userGuess = 100;
	

	//random number generator
	srand((unsigned)time (&t)); 						
	secretNumber = rand() % 21;

	printf("this is a guessing game. I have a number in my head between one to twenty - make guesses and i will tell you if you are too high or too low\n\n\n\n");
	printf("secretNumber : %d\n\n\n\n", secretNumber);
	
	while(userGuess != secretNumber ){
		printf("you have %d guesses left, enter what you think my number is:", guessesLeft);
		scanf("%d",&userGuess);
		if(userGuess>20){
			printf("your number is over 20  - try again\n");
			continue;
		}
		else if(userGuess<0){
			printf("my number isn't less than zero");
			continue;
		}
		else if(userGuess>secretNumber){
			printf("your number is too large\n");
			guessesLeft--;
		}
		else if(userGuess<secretNumber){
			printf("your number is too small\n");
			guessesLeft--;
		}
		else if(secretNumber == userGuess){
			printf("you guessed the right number - you win");
			break;
		}
	}
	
	printf("\nend of game - rerun the program to try again");

  return 0;
}