#include <iostream>
using namespace std;
int main()
{
int cx;
float gls, cf;
printf("*=*=*=*=*=*=*=*=*=*\n");
printf("1 夏利\n");
printf("2 富康\n");
printf("3 桑塔纳\n");
printf("*=*=*=*=*=*=*=*=*=*\n");
printf("输入车型 \t");
scanf("%d", &cx);
printf("输入公里数\t");
scanf("%f", &gls);
switch (cx)
{
case 1:
cf = 7;
if (gls > 3)
cf += (gls - 3) * 2.1;
break;
case 2:
cf = 8;
if (gls > 3)
cf += (gls - 3) * 2.4;
break;
case 3:
cf = 9;
if (gls > 3)
cf += (gls - 3) * 2.7;
break;
default:
printf("error");
}
printf("车费%f\n", cf);
}
如有帮助,望采纳!谢谢!
C++代码如下,如有帮助,请帮忙采纳一下,谢谢。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int cx;
double gls,fy;
cout << "请输入车型(1夏利;2富康;3桑塔纳)和公里数:";
cin >> cx >> gls;
if (cx == 1)
{
if(gls <= 3) fy=7;
else fy = 7 + (gls-3)*2.1;
}else if (cx == 2)
{
if(gls <=3) fy = 8;
else fy = 8 + (gls-3)*2.4;
}else if (cx == 3)
{
if(gls <=3) fy = 9;
else fy = 9 +(gls-3)*2.7;
}else
{
cout << "输入错误"<<endl;
return 0;
}
cout << "费用:" <<fixed << setprecision(1)<< fy<<endl; //保留1位小数
return 0;
}