请看这段c语言代码有什么错误?

来源:百度知道 编辑:UC知道 时间:2024/05/30 11:45:28
#include<stdio.h>
main()
{ int s;
printf("Enter if you are rank 1 or 2 or 3.\n");
scanf("%d",&s);
if(s=1)
printf("Small\n");
else
if(s=2)
printf("Medium\n");
else
if(s=3)
printf("Big\n");
else
printf("What's wrong with you?\n");
}
各位大虾帮我看看有没有什么问题,执行时不管输入什么东西都只显示small

第一个你是怎么排版的这么乱!!

#include<stdio.h>
main()
{ int s;
printf("Enter if you are rank 1 or 2 or 3.\n");
scanf("%d",&s);
if(s=1)
printf("Small\n");
else
if(s=2)
printf("Medium\n");
else
if(s=3)
printf("Big\n");
else
printf("What's wrong with you?\n");
}

第二个就是你的s=1你知道是什么意思吗?
是赋值!!所以每一次都在s=1,s 被赋值为1,所以执行时不管输入什么东西都只显示small

把s=1改为s==1就可以了,以下雷同!

#include<stdio.h>
main()
{ int s;
printf("Enter if you are rank 1 or 2 or 3.\n");
scanf("%d",&s);
if(s==1)
printf("Small\n");
else
if(s==2)
printf("Medium\n");
else
if(s==3)
printf("Big\n");
else
printf(