#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX_NUMBER 100
int initiallize_number_generator()
{
srand((unsigned)time(NULL));
return rand()%MAX_NUMBER+1;
}
void read_guess(int secrete_number)
{
int guess,guess_number=0;
for(;;)
{
printf("please enter your number");
scanf("%d",&guess);
guess_number++;
if(guess==secrete_number)
{
printf("you won");
return;
}
if(guess<secrete_number)
{
printf("your guess is too low,please agian");
}
if(guess>secrete_number)
{
printf("your guess is too high,please again");
}
}
}
int main()
{
char command;
int secrete_number;
secrete_number=initiallize_number_generator();
do{
printf("please begin guess number");
read_guess(secrete_number);
printf("\n");
printf("play again? please enter y/n");
scanf("%c",&command);
}while(command=='y'||command=='Y');
return 0;
}
wangxinfeng6666_749290079 2011-5-12 19:11
用户1409644 2011-5-12 16:52