✔ 最佳答案
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(int argc, char* argv[])
{
char answer[200];
time_t t;
int guess,outcome;
const maxNumber=10; // change this line for a diff.max.
srand((unsigned) time(&t));
do
{
outcome=rand()%maxNumber+1;
printf("Enter your guess from 1 to %d:",maxNumber);
scanf("%s",answer);
if((guess=atoi(answer))>0)
{
if(guess==outcome)
{
printf("Congratulations, you guessed the right number!\n");
} else
{
printf("Sorry, the correct answer is %d\n",outcome);
}
printf("To quit, enter q\n");
} else break;
}while(strlen(answer)>0);
printf("Thank you for playing the number guessing game!\n");
return 0;
}
2007-12-22 12:50:19 補充:
Sorry about the misunderstanding of the question.I have made another one which makes blind guesses. User does not have to answer Hi or low, just yes or no. Hope that's what you want.It is too long to be posted here, so visit:
http://mathmate.brinkster.net/programming.htm