在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%
热门推荐
2 圆圆的祝福语简短
10 永远漂亮祝福语女生简短
11 六一祝福语简短感动女生
12 3岁孩子祝福语简短
13 父亲祝福语大全简短语
14 杨奕老师祝福语简短
15 考试祝福语日文简短版
16 中考祝福语简短卡片大全
17 新年祝福语简短聪明可爱
18 简短朋友旅行祝福语大全