A guessing number program

2007-12-16 8:07 pm
Can anyone pls tell me how to write this program in Turbo C++ ??
thx

回答 (1)

2007-12-17 12:08 pm
✔ 最佳答案
#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&#39;s what you want.It is too long to be posted here, so visit:http://mathmate.brinkster.net/programming.htm


收錄日期: 2021-04-13 14:44:09
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20071216000051KK01265

檢視 Wayback Machine 備份