在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 教师闺蜜祝福语简短