Guessing Game – C


#include<math.h>

#include<stdio.h>

#include<stdlib.h>

void guess (int N){

int number, guess, numberOfGuess = 0;

printf("Guess a number between 1 to %dn", N);

//Using do-while loop will let the compiler determine the correct number

do {

if (numberOfGuess > 9){

printf("You Loose!n");

break;

}


scanf("%d", &guess);

if(guess > number){

printf("Lower the number please!n");

numberOfGuess++;

}

else if(number > guess){

printf("Higher the number please!n");

numberOfGuess++;

}

else

printf("You have guessed the number in %d attempts\n", numberOfGuess);




} while(guess != number);

}

int main()

{

int N = 100;

//Function call

guess(N);

return 0;

}

Scroll to top