要支付的金额通常是通过将单价乘以销售数量来计算的。但是,以下情况适用:
给那个项目。
给予折扣。
给定
#include <iostream>
using namespace std;
int main(){
int items;
int i=0;
int item_num;
double unit_price;
double price_break;
double quantity_sold;
double amount_paid;
double discount=0.00;
double net_payment;
amount_paid=unit_price*quantity_sold;
if(quantity_sold>=price_break){
discount=0.1*amount_paid;
new_amount=amount_paid-discount
//Quantity sold is more than price break which places discount at 10%
net_payment=new_amount;
}else{
//Need help with this. How do I further add 5%?
if((quantity_sold>=price_break)&&(new_amount>1000)){
discount=0.1*amount_paid;
net_payment=amount_paid-discount;
}
else{
if(amount_paid>1000){
// discount is 5% since the amount to be paid exceeds $1000
discount=0.05*amount_paid;
net_payment=amount_paid-discount;
}
else{
if(quantity_sold<price_break){
//No discount and the amount to be paid doesn't exceeds $1000
net_payment=amount_paid;
}
}
}
}
最佳答案
由于第二个和第三个条件导致相同的事情发生,您可以将规则简化如下:
因此,只需去掉外部
else
中的 if
块,而只需测试金额是否超过 1,000 美元。amount_paid=unit_price*quantity_sold;
if(quantity_sold>=price_break){
// apply first discount if quantity is high enough
discount=0.1*amount_paid;
amount_paid-=discount;
}
if(amount_paid>1000){
// discount is 5% since the amount to be paid exceeds $1000
discount=0.05*amount_paid;
amount_paid-=discount;
}
关于c++ - 我要在什么条件下进一步增加 5% 的折扣?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53017686/