谁能用最初级的语言编写一下这段程序

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:26:36
先由计算机随机生成一个1到100的数请人猜,如果人猜对了,在屏幕上输出输了多少次才猜对此数,以此来反映猜数者的运气水平,且结束游戏,否则计算机给出提示,告诉猜数人所猜的数是太大了还是太小了,最多猜10次,如果猜了10次还未猜中,则停止本次猜数,然后继续猜下一个数。每次运行可以猜多个数,直到操作者想停止时才结束。
===============================================
最最简单的语言,然后如果能说明一下最好,那个想停止时才结束指的是用关闭,也就是右上角的小X,所以不用管。

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

void main()
{
srand( (unsigned) (time(NULL)) );//初始化伪随机数种子

int right;
int trytime;
int guess;
while(1)
{
right = rand()%100+1;//产生一个随机数
trytime = 0;
while(trytime++ < 10)//10次机会
{

printf("Please guess the number: (%d/10) (Input -1 to exit)\n",trytime);//输入-1退出
scanf("%d",&guess);

if(guess==-1)
exit(0);
else if(guess>right)
printf("Your answer is greater. Try again.\n");//提示更大
else if(guess<right)
printf("Your answer is less. Try again.\n");//提示更小
else
{
printf("Congratulation, the answer you gave is correct! \n");//答对,换个数字
break;
}

}
if(trytime==11)//答错10次
{