#include
#include
#include
int main(void)
{
int guess =0;
int chosen=0;
double limit =0.0L;
bool faithtest = false;
int chance =0;
printf("\nThis is a guessing game,and now you need to enter a Positive Integer number as the upper limit for generating random numbers, the minimum of 1");
// now faith test//
for( ;!faithtest;)
{
scanf("%f",&limit);
if((int)limit == limit)
faithtest == true;
else
printf("\nA Positive Integer is needed!Please try again!");
}
// the main achitecture of the game //
srand(time(NULL));
chosen = 1 + rand()%limit;
printf("\n\nI have chosen a lucky number between 1 and %d,please find it out.",limit);
printf("\n\nNow enter the number and press 'enter' key!");
printf("\nObviously,I will count the chance you used.");
for( ; ;++chance)
{
scanf("%d",&guess);
if(guess == chosen)
break;
else
printf("\nSorry it's wrong.Now you have used %d time%s.",chance,chance ==1?"":"s");
}
printf("\nCongratulations!The number was %d.You have wasted %d time%s",chosen,chance,chance ==1?"":"s");
system("pause");
return 0;
}
编译器提示: chosen = 1 + rand()%limit; 这句导致编译失败
另外,把这句删掉以后,编译成功,但是没有窗口运行出来
编译器:啊哈C