Guessing Game in C

Hello student today we learn Making a guessing game program in C. Using conditional function if() and while(), Guessing Game in C.

Building A Guessing Game

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()

{

int Guess, Random_Number;int y ;
char choice = ‘y’;

while(choice == ‘y’)
{

printf(“\n\t\t\t\t\t\t >>>>>>>>>GUESSING GAME<<<<<<<<“);

time_t t;
srand((unsigned) time (&t));
Random_Number=rand()%8+1;
printf(“\n\n%d”,Random_Number);

do
{
printf(” I have a number between 1 and 10.\nCan you guess my number? \nPlease type your first guess:”);
scanf(“%d”,&Guess);
if(Random_Number>Guess)
{
printf(“\n Too low. Try again”);
printf(“\n”);
}
else if(Random_Number<Guess)
{
printf(“Too High. Try again”);
printf(“\n”);
}

}

while(Random_Number != Guess);
getchar();
printf(“\n you win !! \n\n do you wanna play again (y or n)”);

scanf(“%c”,&choice);

}
return 0;
}

Guess my number program in C

If first is not Run! Try this one 😊
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main()

{

int Guess, Random_Number;int y ;

char choice = ‘y’;

int isPlaying=1;

while(isPlaying)

{

printf(“\n\t\t\t\t\t\t >>>>>>>>>GUESSING GAME<<<<<<<<“);

time_t t;

srand((unsigned) time (&t));

Random_Number=rand()%4+1;

//printf(“\n\n%d”,Random_Number);

do

{

printf(“\nI have a number between 1 and 1000.\nCan you guess my number? \nPlease type your first guess:”);

scanf(“%d”,&Guess);

if(Random_Number>Guess)

{

printf(“\n Too low. Try again”);

printf(“\n”);

}

else if(Random_Number<Guess)

{

printf(“Too High. Try again”);

printf(“\n”);

}

}

while(Random_Number != Guess);

getchar();

printf(“\n you win !! \n\n do you wanna play again (y or n)”);

scanf(“%c”,&choice); switch(choice)

{

case ‘y’: case ‘Y’: isPlaying=1;

break;

case ‘n’: case ‘N’: isPlaying=0;

break;

}

} return 0;

}

Random number guessing program in C

Guessing Game in C
Guessing Game in C
Guessing Game in C
Guessing Game in C

2nd Run

Guessing Game in C
Guessing Game in C

2nd Run Output

Guessing Game in C
Guessing Game in C

3rd Run

Guessing Game in C
Guessing Game in C
Guessing Game in C
Guessing Game in C

Note:- This gaming loop is Repititing until you Exit it.

Game in C

 

END

C program to draw a square using graphics (clickHere)

Note:- Maybe sometime above code doesn’t get user-friendly output, in codeblock ‘or’ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.

Also Read

Types of functions in C    Read Here

I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “Guessing Game in C

. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Guessing Game in C  or My website.

Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt

I request you if you have any doubt or question regarding our site, then please don’t hesitate. We always waiting for your Suggestion.

Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of  Guessing Game in C

For further questions, you can contact us Via mail [email protected]  otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.

thesmolt App

 

Leave a Reply

x