從給定的售價和利潤或虧損百分比查詢 C++ 的成本價


假設我們已有售價,並給出了利潤或虧損的百分比。我們必須找出產品的成本價。公式如下 −

$$成本價 = \frac{售價 * 100}{100 + 利潤百分比}$$

$$成本價 = \frac{售價 *100}{100 + 虧損百分比}$$

示例

 線上演示

#include<iostream>
using namespace std;
float priceWhenProfit(int sellPrice, int profit) {
   return (sellPrice * 100.0) / (100 + profit);
}
float priceWhenLoss(int sellPrice, int loss) {
   return (sellPrice * 100.0) / (100 - loss);
}
int main() {
   int SP, profit, loss;
   SP = 1020;
   profit = 20;
   cout << "Cost Price When Profit: " << priceWhenProfit(SP, profit) << endl;
   SP = 900;
   loss = 10;
   cout << "Cost Price When loss: " << priceWhenLoss(SP, loss) << endl;
}

輸出

Cost Price When Profit: 850
Cost Price When loss: 1000

更新於: 18-Dec-2019

231 次瀏覽

啟動您的職業生涯

完成課程獲得認證

開始吧
廣告
© . All rights reserved.