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;
}
}
}
}

Comments

  1. which app you used to run this program
    please tell

    ReplyDelete
    Replies
    1. cxx driod
      for mobile in play store
      gcc
      for computer in google

      Delete

Post a Comment

Popular posts from this blog

Snake game.c

Type declaration

Array with function