c program number guessing game
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
int randomnum;
int userinput;
void generate()
{
srand(time(NULL));
randomnum = 1 + rand() % 10;
}
void welcomemeg()
{
printf("welcome to number guessing game \n");
printf("type number between 1-10\n>>");
generate();
scanf("%d", &userinput);
}
int main()
{
bool isgameover = false;
welcomemeg();
while(! isgameover)
{
if (userinput < randomnum)
{
printf("try some thing big\n");
scanf("%d", &userinput);
}
else if (userinput > randomnum)
{
printf("try some thing small\n");
scanf("%d", &userinput);
}
else
{
printf("you won the game\n");
printf("try again by typing y or just click enter to exit\n");
getchar();
char userchoice;
char y;
scanf("%c",&y);
userchoice = getchar();
if (userinput = y){
welcomemeg();
}
else
{
printf("bye bye !\n");
isgameover = true;
}
}
}
}
very cool i like this game
ReplyDeletewhich app you used to run this program
ReplyDeleteplease tell
cxx driod
Deletefor mobile in play store
gcc
for computer in google