问题描述
- 这个c程序哪里错了?????
-
#include
int main(void)
{
const int danjia = 5;
int shuliang = 0;
int zongjia = 0;
int zan = 0;
printf("shurushuliang:");
scanf("%d",&shuliang);
zan = shuliang * danjia;
{
if((zan > 30) && (zan <= 50))
zongjia = shuliang*danjia*0.1;
printf("%d",zongjia);
if(zan > 50)
zongjia = shuliang*danjia*0.15;
printf("%d",zongjia);
else
printf("%d",shuliang*danjia):
return 0:}
}
就是提示出错,但我就是找不到哪里错了。。。。。
解决方案
丢大括号,还有分号写成冒号
const int danjia = 5;
int shuliang = 0;
int zongjia = 0;
int zan = 0;
printf("shurushuliang:");
scanf("%d",&shuliang);
zan = shuliang * danjia;
if((zan > 30) && (zan <= 50))
{
zongjia = shuliang*danjia*0.1;
printf("%d",zongjia);
if(zan > 50)
zongjia = shuliang*danjia*0.15;
printf("%d",zongjia);
}
else
printf("%d",shuliang*danjia);
return 0;
解决方案二:
注意语句结束是;号,不是:,另外括号是英文的,不是中文
int main(void)
{
const int danjia = 5;
int shuliang = 0;
int zongjia = 0;
int zan = 0;
printf("shurushuliang:");
scanf("%d",&shuliang);
zan = shuliang * danjia;
{
if((zan > 30) && (zan <= 50)){
zongjia = shuliang*danjia*0.1;
printf("%d",zongjia);
}else if(zan > 50){
zongjia = shuliang*danjia*0.15;
printf("%d",zongjia);
}
else
printf("%d",shuliang*danjia);
return 0;
}
}
解决方案三:
#include
#include
int main()
{
const int danjia = 5;
int shuliang = 0;
int zongjia = 0;
int zan = 0;
printf("shurushuliang:");
scanf("%d",&shuliang);
zan = shuliang * danjia;
if((zan > 30) && (zan <= 50))
{
zongjia = shuliang*danjia*0.1;
printf("%d",zongjia);
if(zan > 50)
{
zongjia = shuliang*danjia*0.15;
printf("%d",zongjia);
}
else
printf("%d",shuliang*danjia);
}
return 0;
}
解决方案四:
如果是编译的错误,按编译器提供的错误行对此行代码进行分析。
如果目测一下没有错误,就可以注意标点符号,特别半角/全角符号的区分。
解决方案五:
建议你换成vs吧,这种错误他会直接提示的
解决方案六:
你这个代码挺多错误的。我都帮你改好了,有几处是标点符号的使用错误,有括号忘记扩回来了。还有就是有一点,虽然你应该是初学者,但是头文件还是要加进去比较好,以后才不会忘记。
#include <stdio.h>
int main(void)
{
const int danjia = 5;
int shuliang = 0;
int zongjia = 0;
int zan = 0;
printf("shurushuliang:");
scanf("%d",&shuliang);
zan = shuliang * danjia;
{
if((zan > 30) && (zan <= 50))
zongjia = shuliang*danjia*0.1;
else if(zan > 50){
zongjia = shuliang*danjia*0.15;
printf("%d",zongjia);}
else
printf("%d",shuliang*danjia);
return 0;
}
}
解决方案七:
头文件没有,分号打错了
解决方案八:
头文件没有,建议程序if else的输出都加到花括号里,要不就每次都输出。