C++ to realize the small game guess

  • 2020-07-21 09:30:09
  • OfStack

Make it simple today


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
 int a,b;
 char c;
  srand(time(NULL));
 a=1+(rand()%1000);
 printf(" I have a 1 somewhere 1 and 1000 The number between \n Can you guess the number I want ?\n Please enter your guess .\n");
 scanf("%d",&b);
 while(b!=-1)
 {
 if(b==a)
 {
 printf(" Right! \n Do you want to play again 1 Time? (yes( is ) or no (no ))?");
 scanf("%c",&c);
 scanf("%c",&c);
 switch(c){
 case 'y':
  printf(" I have a 1 somewhere 1 and 1000 The number between \n Can you guess the number I want ?\n Please enter your guess .\n");
     scanf("%d",&b);
  break;
 case 'n':
  break;
 }
 }

 while(b<a)
 
 {
 printf(" Too few. Try again 1 time \n");
 scanf("%d",&b);
 }

 while(b>a)
 {
 printf(" It's too big. Try again 1 time \n");
 scanf("%d",&b);
 }
 }
}


Related articles: