在C ++ 找到折扣百分比的程序
在本教程中,我们将讨论一个找到折扣率的程序。
为此,我们将为您提供项目的标价和销售价格。我们的任务是计算并打印出该商品的折扣百分比。
示例
#include <bits/stdc++.h>
using namespace std;
//寻找折扣率
float discountPercentage(float S, float M) {
float discount = M - S;
float disPercent = (discount / M) * 100;
return disPercent;
}
int main() {
int M, S;
M = 120;
S = 100;
cout << std::fixed << std::setprecision(2) << discountPercentage(S, M) << "%" << endl;
M = 1000;
S = 500;
cout << std::fixed << std::setprecision(2) << discountPercentage(S, M) << "%" << endl;
return 0;
}输出结果
16.67% 50.00%