以下程序运行结果不对,但是我没检查出来
有以下程序,用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元时,结果不对啊,是哪里出错了?