在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%
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短