首页上一页 1 下一页尾页 1 条记录 1/1页
【例7.7】 使用switch语句计算运输公司的计费。 求助,错误提示看不懂
发表在C语言图书答疑
2016-10-17
是否精华
是
否
版块置顶:
是
否
#include<stdio.h>
int main()
{
int idiscount;
int ispace;
int iswitch;
float fprice,fweight,fAllprice;
printf("enter the price,weight and space\n");
scanf("%f%f%d",&fprice,&fweight,&ispace);
if(ispace>3000)
{
iswitch=12;
}
else
{
iswitch=ispace/250;
}
switch(iswitch)
{
case 0:
idiscount=0;
break;
case 1:
idiscount=2;
break;
case 2:
case 3:
idiscount=5;
break;
case 4:
case 5:
case 6:
case 7:
idiscount=8;
break;
case 8:
case 9:
case 10:
case 11:
idiscount=10;
break;
case 12:
idiscount=15;
break;
default:
break;
}
fAllprice=ispace*fprice*(1-idiscount/100.0);
printf("Allprice is :%.4f\n",fAllprice);
return 0;
}
--------------------Configuration: 2 - Win32 Debug--------------------
Linking...
2.1.obj : error LNK2005: _main already defined in 2.obj
Debug/2.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
2.exe - 1 error(s), 0 warning(s)
int main()
{
int idiscount;
int ispace;
int iswitch;
float fprice,fweight,fAllprice;
printf("enter the price,weight and space\n");
scanf("%f%f%d",&fprice,&fweight,&ispace);
if(ispace>3000)
{
iswitch=12;
}
else
{
iswitch=ispace/250;
}
switch(iswitch)
{
case 0:
idiscount=0;
break;
case 1:
idiscount=2;
break;
case 2:
case 3:
idiscount=5;
break;
case 4:
case 5:
case 6:
case 7:
idiscount=8;
break;
case 8:
case 9:
case 10:
case 11:
idiscount=10;
break;
case 12:
idiscount=15;
break;
default:
break;
}
fAllprice=ispace*fprice*(1-idiscount/100.0);
printf("Allprice is :%.4f\n",fAllprice);
return 0;
}
--------------------Configuration: 2 - Win32 Debug--------------------
Linking...
2.1.obj : error LNK2005: _main already defined in 2.obj
Debug/2.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
2.exe - 1 error(s), 0 warning(s)