从给定的售价和利润或亏损百分比查找 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP