标题:以下程序运行结果不对,但是我没检查出来
只看楼主
随风晨爱
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2017-6-1
结帖率:91.67%
已结贴  问题点数:6 回复次数:3 
以下程序运行结果不对,但是我没检查出来
有以下程序,用switch语句,为了打折促销,1000元以上打9.5折,2000元以上打9折,3000元以上打8.5折,5000元以上打8折,程序如下#include <iostream>
using namespace std;
int main()
{
    int c;
    float total_payment, discount_rate, real_payment;
    cout << "plase input total_payment for goods:";
    cin >> total_payment ;
    c = total_payment / 1000;
    switch(c)
    {
        case 0: discount_rate=1; break;
        case 1: discount_rate=0.95; break;
        case 3: discount_rate=0.9; break;
        case 4:
        case 5: discount_rate=0.85; break;
        difault : discount_rate=0.8; break;
    }
    real_payment = discount_rate * total_payment;
    cout << "the real payment is:" << real_payment << endl;
    return 0;
}
可是当输入8000元时,结果不对啊,是哪里出错了?
搜索更多相关主题的帖子: 运行 结果 检查 case break 
2018-10-19 15:36
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:2 
difault 这个关键字都拼写错了!
再者你的代码
程序代码:
switch(c)
{
    case 0: discount_rate=1; break;
    case 1: discount_rate=0.95; break;
    case 3: discount_rate=0.9; break;
    case 4:
    case 5: discount_rate=0.85; break;
    difault : discount_rate=0.8; break;
}
和要求“1000元以上打9.5折,2000元以上打9折,3000元以上打8.5折,5000元以上打8折”也不符吧

2018-10-19 16:00
随风晨爱
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2017-6-1
得分:0 
回复 2楼 rjsp
那应该怎么写呢,错误的地方已经改了
2018-10-19 16:14
rohalloway
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:97
专家分:405
注 册:2018-9-28
得分:4 
程序代码:
#include <iostream>
using namespace std;

int main()
{
    int c;
    float total_payment, discount_rate, real_payment;
    cout << "plase input total_payment for goods:";
    cin >> total_payment;
    c = total_payment / 1000;
    switch (c)
    {
    case 0: discount_rate = 1; break;
    case 1: discount_rate = 0.95; break;
    case 2: discount_rate = 0.9; break;
    case 3: discount_rate = 0.85; break;
    case 4: discount_rate = 0.85; break;
    default: discount_rate = 0.8; break;
    }
    real_payment = discount_rate * total_payment;
    cout << "the real payment is:" << real_payment << endl;
    return 0;
}
2018-10-20 03:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-490515-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.506568 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved