在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 婆婆高寿祝福语大全简短