竟然需要输入两个值,而且出现的是第一次的结果跟第二次没关系

img


我的思路是:先是一个for循环来记次数如果次数大于五就停止运行,然后是if循环来判断是否是1-4其他的输出等于零,如果遇到输入为零的话就停止运行

#include<stdio.h>
int main()
{
int i,type;
printf("[1] apple\n[2] pear\n[3] orange\n[4] grape\n[0] exit");

for(i=1;;i++){
    scanf("%d ",&type);
    if(type==0)break;
    else if(type==1)printf("price = 3.00\n");
    else if(type==2)printf("price = 2.50\n");
    else if(type==3)printf("price = 4.10\n");
    else if(type==4)printf("price = 10.20\n");
    else printf("price = 0.00\n");
    if(i>5)return 0;
    }
return 0;

}

空格去掉呀

img