简单的猜数程序,求指教,有疑惑啊!!
下面这段程序是简单的猜数程序,这里我有几个问题不懂啊!1,这个防止非法输入的ret应该怎么定义。
2,为什么我输入数字之后都能显示正确输出,但是一旦输入字母之后,在输入一个数字程序就自动崩溃!!
求
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int guess,count=0,i=1;
float magic;
float ret;
srand(time(NULL));
magic=rand()%100+1;
do{
printf("please input guess:\n");
ret=scanf("%d",&guess);
while(ret!=1)
{
while(getchar()!='\n');
printf("plese input a guess:\n");
ret=scanf("%d",guess);
}
count++;
if(guess>magic)
{
printf("the guess too high\n");
}
else if(guess<magic)
{
printf("the guess too low\n");
}
else
{
printf("you are right\n");
}
printf("count=%d\n",count);
i++;
}while(guess!=magic&&i<10);
}