要支付的金额通常是通过将单价乘以销售数量来计算的。但是,以下情况适用:

  • 如果售出的数量大于或等于价格中断数量,则 10% 的折扣是
    给那个项目。
  • 如果给予折扣,并且要支付的新金额超过 $1000.00,则再增加 5%
    给予折扣。
  • 如果没有打折,并且支付的金额超过 $1000.00,那么 5% 的折扣是
    给定

  • #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;
                    }
                }
            }
        }
    

    最佳答案

    由于第二个和第三个条件导致相同的事情发生,您可以将规则简化如下:

  • 首先,如果售出的数量大于或等于价格中断数量,则对该商品给予 10% 的折扣。
  • 无论在步骤 1 中是否给予折扣,如果要支付的金额超过 1,000 美元,则给予 5% 的折扣。

  • 因此,只需去掉外部 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/

    10-13 00:08