```c++
#include<iostream>
//#include<iomanip>
#include<stdio.h>
using namespace std;
int main()
{
double t = 0, cost = 0;
double a = 5.00;
double b = 40.00;
cin >> t;
if (t <= 24)
{
if (t <= 3)
{
cout << a << endl;
}
else if (t >= 17.5)
{
cout << b << endl;
}
else
{
cost = a + (t - 3) * 2;
printf("%.2f", cost);
//cout << fixed << showpoint << setprecision(2) << cost << endl;
}
}
return 0;
}
#include <iomanip>
cout << fixed << setprecision(2) << a << endl;
cout << fixed << setprecision(2) << b << endl;
cout << fixed << setprecision(2) << cost << endl;
你最后那里少了一个总长度
下面是网上找来的例子
//输出小数点后两位
int pi=3.1415;
printf("%3.2f",pi);//%m.nf中m是值输出数据的总宽度,n是小数点位数