在 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
廣告