C++程式查詢折扣百分比


在這個問題中,我們得到了兩個數字,它們定義了某個產品的標價 (M) 和售價 (S)。我們的任務是建立一個C++程式來查詢折扣百分比

折扣是指從產品實際價格(標價)中扣除的金額。

折扣公式為:

discount = marked price - selling price

折扣百分比是從產品實際價格中扣除的價格百分比。

折扣百分比的公式為:

discount percentage = (discount / marked price ) * 100

讓我們舉個例子來理解這個問題:

輸入

240, 180

輸出

25%

解釋

Discount = (240 - 180) = 60
Discount percentage = (60/240)*100 = 25%

解決方案方法

折扣和折扣百分比的公式為:

Discount = marked price - selling price
Discount percentage = (discount / marked price ) * 100

程式說明我們解決方案的工作原理:

示例

 線上演示

#include <iostream>
using namespace std;
int main() {
   float MP = 130, SP = 120;
   float DP = (float)(((MP - SP) * 100) / MP);
   printf("The discount percentage on the given product is %.2f\n", DP);
   return 0;
}

輸出

The discount percentage on the given product is 7.69

更新於: 2020年9月16日

784 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

立即開始
廣告

© . All rights reserved.