这个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:

}

}

就是提示出错,但我就是找不到哪里错了。。。。。

c

8个回答

丢大括号,还有分号写成冒号

 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的输出都加到花括号里,要不就每次都输出。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!