Guess game with C

Shared by: devcanvas

c

1
# include <stdio.h>
2

3
int main(){
4
    int guess, attempt, number;
5
    char message[] = "Game over";
6
    number = 5;
7
    attempt = 3;
8
    for (int i = 0; i <= attempt; attempt--){
9
	    printf("Guess a Number:");
10
	    scanf("%d", &guess);
11
	   if (guess == number){
12
		   printf("You guessed it correctly!! %d:%d\n", guess,number);
13
		   break;
14
	   }else{
15
		printf("Try again!, you have %d chance left\n", attempt);
16
	   }
17
    }
18
    printf("The number you entered is %d\n", guess);
19
}
20

21
// QQQ
Love it? Share it!

DevCanvas DevCanvas Logo

Online Editor with a collection of awesome frontend code and code snippets for developers of all levels.

Legal & Support

Stand with Palestine 🇵🇸! DO NOT BE SILENCED

© 2025 DevCanvas. All rights reserved.