本题要求根据某城市普通出租车收费标准编写程序进行车费计算。具体标准如下:
起步里程为3公里,起步费10元;
超起步里程后10公里内,每公里2元;
超过10公里以上的部分加收50%的回空补贴费,即每公里3元;
营运过程中,因路阻及乘客要求临时停车的,按每5分钟2元计收(不足5分钟则不收费)。
输入格式:
输入在一行中给出输入行驶里程(单位为公里,精确到小数点后1位)与等待时间(整数,单位为分钟),其间以空格分隔。
输出格式:
在一行中输出乘客应支付的车费(单位为元),结果四舍五入,保留到元。
输入样例1:
2.6 2
输出样例1:
10
输入样例2:
5.1 4
输出样例2:
14
输入样例3:
12.5 9
输出样例3:
34
我写的代码
#include
int main() {
float s;
int t;
scanf("%.1f%d", &s, &t);
if (t < 5) {
if (s <= 3)
printf("10");
else if (s > 3 && s < 10)
printf("%d", 2 * (s - 3) + 10);
else if (s >= 10)
printf("%d", 10 + (s - 3) * 3 );
} else if (t > 5) {
if (t % 5 != 0) {
if (s > 3 && s < 10)
printf("%d", 2 * (s - 3) + 10 + (t / 5 + 1) * 2);
else
#include<stdio.h>
int main()
{
double n,m1;
int t,m2;
scanf("%lf %d",&n,&t);
if(n<=3){
m1=10;
}
else if(n>3&&n<10){
m1=10+(n-3)*2;
}
else{
m1=24+(n-10)*3;
}
m2=(t/5)*2;
printf("%.0lf",m1+m2);
return 0;
}
scanf("%.1f%d", &s, &t);
改成
scanf("%f%d", &s, &t);
你这代码不全 else后面呢 我这直接给你一个完整的 你学习参考一下 【望采纳】
#include <stdio.h>
int main()
{
float a;
int b,temp;
scanf("%f %d",&a,&b);
if(a<=3){
temp=10;
}
else if(a>3&&a<=10){
temp=(int)(10+(a-3)*2+0.5);
}
else{
temp=(int)(24+(a-10)*3+0.5);
}
printf("%d",temp+(b/5*2));
return 0;
}
大概是这样,可以参考一下
#include <stdio.h>
int main(void){
double a,temp=10;
int b;
scanf("%lf%d",&a,&b);
if(a<=3){
if(b<5)
printf("路费:%.0lf\n",temp);
else{
temp+=b/5*2;
printf("路费:%.0lf\n",temp);
}
}else{
temp+=(a-3)*3;
if(b<5)
printf("路费:%.0lf\n",temp);
else{
temp+=b/5*2;
printf("路费:%.0lf\n",temp);
}
}
return 0;
}
私信解决
#include <bits/stdc++.h>
int main()
{
float a;
int b,temp;
scanf("%f %d",&a,&b);
if(a<=3){
temp=10;
}
else if(a>3&&a<=10){
temp=(int)(10+(a-3)*2+0.5);
}
else{
temp=(int)(24+(a-10)*3+0.5);
}
printf("%d",temp+(b/5*2));
return 0;
}