优惠购物c++ switch
时间: 2023-10-20 21:32:33 浏览: 188
switch_C++_
根据引用和引用提供的信息,可以使用switch语句编写一个关于商场购物金额优惠的程序。根据顾客购物小票上的消费金额,程序会输出顾客将享受的折扣与打折后需支付的金额。
```C++
#include <iostream>
using namespace std;
int main() {
double x;
cin >> x;
int y;
y = x / 500;
switch(y) {
case 0:
cout << "discount: " << "No discount! " << "price: " << x << endl;
break;
case 1:
cout << "discount: " << "9 " << "price: " << 0.9 * x << endl;
break;
case 2:
case 3:
cout << "discount: " << "8 " << "price: " << 0.8 * x << endl;
break;
case 4:
case 5:
cout << "discount: " << "7 " << "price: " << 0.7 * x << endl;
break;
case 6:
case 7:
case 8:
case 9:
cout << "discount: " << "6 " << "price: " << 0.6 * x << endl;
break;
default:
cout << "discount: " << "5 " << "price: " << 0.5 * x << endl;
}
return 0;
}
```
这段程序使用了switch语句,根据顾客购物的消费金额进行不同的判断,然后输出相应的折扣和打折后的支付金额。在程序中,将顾客的消费金额除以500得到的商作为判断的依据,然后根据不同的商值进行不同的情况处理,最后输出相应的折扣和支付金额。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C++Switch语句的用法](https://blog.csdn.net/uuup_/article/details/120478111)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [c语言 如何用switch语句编写一个有关商场购物金额优惠的选择程式](https://blog.csdn.net/weixin_39599097/article/details/117142369)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文