#include <stdio.h>
#include <stdlib.h>
#include<time.h>//加上此头文件的作用是什么?另外不加的话有什么影响?
//随机生成一个1~100的数字
int getRandomNumber()
{
srand((unsigned int)time(0));
return (rand()%100)+1;
}
//定义一个对猜数字游戏所用次数的结果的判断
void GuessResult(int counter)
{
switch(counter)
{
case 1:
case 2:
case 3:
case 4:
printf("Are you Genius?\n");
break;
case 5:
case 6:
case 7:
printf("Your score is just all right!\n");
break;
case 8:
case 9:
case 10:
printf("Just so so!\n");
break;
case 11:
case 12:
printf("Bad Score!!!\n");
break;
default:
printf("Are you want to case me?");
break;
}
}
//核心代码:猜测的过程
void GuessTheNumber()
{
int randomNumber=getRandomNumber();
int counter=1;
int myAnswer;
while(counter)
{
printf("Enter guess number %d:",counter);
scanf("%d",&myAnswer);
if(randomNumber>myAnswer)
{
printf("Too Small!\n");
}
else if(randomNumber<myAnswer)
{
printf("Too bigger!\n");
}
else if(myAnswer==randomNumber)
{
printf("that is correct!\n");
break;
}
else
{
printf("You may input a wrong way,please check it clearly\n");
}
counter++;
}
GuessResult(counter);//我为什么会在此处调用这样的一个函数?
}
//主函数通过调用前面自己定义的函数来执行,是不是感觉主函数一下子变瘦了呢?
int main()
{
printf("Welcome to our Guess_Number_Game\n");
GuessTheNumber();
return 0;
}
/*
//猜数字进阶版,增加了询问是否再来一次的操作
//这个循环操作貌似有点问题,先不调用也罢;
int main()
{
int flag;
printf("Welcome to our Guess_Number_Game\n");
while(flag)
{
GuessTheNumber();
printf("Do you want to play it again?\tYes ,please press '1',No please press any others to exit\n");
scanf("%d",&flag);
if(flag==1)
{
GuessTheNumber();
}
else
{
flag=0;
break;
}
}
return 0;
}
*/
#include <stdlib.h>
#include<time.h>//加上此头文件的作用是什么?另外不加的话有什么影响?
//随机生成一个1~100的数字
int getRandomNumber()
{
srand((unsigned int)time(0));
return (rand()%100)+1;
}
//定义一个对猜数字游戏所用次数的结果的判断
void GuessResult(int counter)
{
switch(counter)
{
case 1:
case 2:
case 3:
case 4:
printf("Are you Genius?\n");
break;
case 5:
case 6:
case 7:
printf("Your score is just all right!\n");
break;
case 8:
case 9:
case 10:
printf("Just so so!\n");
break;
case 11:
case 12:
printf("Bad Score!!!\n");
break;
default:
printf("Are you want to case me?");
break;
}
}
//核心代码:猜测的过程
void GuessTheNumber()
{
int randomNumber=getRandomNumber();
int counter=1;
int myAnswer;
while(counter)
{
printf("Enter guess number %d:",counter);
scanf("%d",&myAnswer);
if(randomNumber>myAnswer)
{
printf("Too Small!\n");
}
else if(randomNumber<myAnswer)
{
printf("Too bigger!\n");
}
else if(myAnswer==randomNumber)
{
printf("that is correct!\n");
break;
}
else
{
printf("You may input a wrong way,please check it clearly\n");
}
counter++;
}
GuessResult(counter);//我为什么会在此处调用这样的一个函数?
}
//主函数通过调用前面自己定义的函数来执行,是不是感觉主函数一下子变瘦了呢?
int main()
{
printf("Welcome to our Guess_Number_Game\n");
GuessTheNumber();
return 0;
}
/*
//猜数字进阶版,增加了询问是否再来一次的操作
//这个循环操作貌似有点问题,先不调用也罢;
int main()
{
int flag;
printf("Welcome to our Guess_Number_Game\n");
while(flag)
{
GuessTheNumber();
printf("Do you want to play it again?\tYes ,please press '1',No please press any others to exit\n");
scanf("%d",&flag);
if(flag==1)
{
GuessTheNumber();
}
else
{
flag=0;
break;
}
}
return 0;
}
*/