#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define NO 0
#define YES 1
int main(int argc, char* argv[])
{
int guess_value;
int number;
int nbr_of_guesses;
int done = NO;
printf ("\n\nGeting a Random number:\n");
srand ((unsigned) time(NULL));
number=rand()%20 + 1;
nbr_of_guesses = 0;
while(done==NO)
{
printf("\nPick number between 0 and 20\n");
cin >> guess_value;
if(guess_value > 20)
cout<<"error please input 0 and 20"<<endl;
else
{
nbr_of_guesses++;
if(number==guess_value)
{
done=YES;
}
else
if(number<guess_value)
{
printf("\nYou guessed high!");
}
else
{
printf("\nYou guesses low!");
}
}
}
printf("\n\nCongratulations!you guessed right in %d guesses",nbr_of_guesses);
printf("\n\nThe number was %d\n\n",number);
return 0;
}
(经VC6.0++编译通过)
我帮你重新写了一个,你自己看看吧,
你里面自己定义就出问题了,还有你让别人从0到32767这样的数字
明显不合理,谁会吃饱了去玩啊,想想合理些的,自己还可以多加些好的游戏
比如做个飞机大站,五子棋等等,对你的C进步会比较快的.
