lebaaa 2023-10-07 22:10 采纳率: 0%
浏览 4

c++初学者运用if嵌套语句遇到问题? 。?

谢谢大家明天的ddl┭┮﹏┭┮
题目要求:

img

代码如下;#include

#include<cmath>
using namespace std;
int main()
{
    double  x,  b, c, t,d, C, B, T;
    char a;
    cout << "输入汽车类型(字母)和入库、出库的时间(h):" << endl;
    cin >> a >> b >> c;
    
    t = c - b;
    if (a == C)
    {
        if (t <= 3) d = 5 * round(t);
        else d = 15 + 10 * round(t - 3);
    }
    else if (a == B)
    {
        if (t <= 2) d = 10 * round(t);
        else d = 20 + 15 * round(t - 2);
    }
    else(a == T)
    {    if (t <= 1) d = 10 * round(t);
        else d = 10 + 15 * round(t - 1);
    }
    cout << "应缴的停车费:" << d;
return 0;
}

系统报错如下:

img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-10-07 22:12
    关注
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
        double  x,  b, c, t,d, C, B, T;
        char a;
        cout << "输入汽车类型(字母)和入库、出库的时间(h):" << endl;
        cin >> a >> b >> c;
        
        t = c - b;
        if (a == C)
        {
            if (t <= 3) d = 5 * round(t);
            else d = 15 + 10 * round(t - 3);
        }
        else if (a == B)
        {
            if (t <= 2) d = 10 * round(t);
            else d = 20 + 15 * round(t - 2);
        }
        else if (a == T)
        {    if (t <= 1) d = 10 * round(t);
            else d = 10 + 15 * round(t - 1);
        }
        cout << "应缴的停车费:" << d;
        return 0;
    }
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 10月7日