zoukankan      html  css  js  c++  java
• # Exercise 3.3 Calculate a discounted price

Exercise 3-3. Write a program that will calculate the price for a quantity entered from
the keyboard, given that the unit price is \$5 and there is a discount of 10 percent for
quantities over 30 and a 15 percent discount for quantities over 50.

``` 1 // Exercise 3.3 Calculate a discounted price
2
3 // I interpreted this exercise as implying that the 10% applies to items 31 to 50
4 // and the 15% applies to items in excess of 50.
5 // That is, you don't get 15% discount on the whole price when you order 51 items.
6
7 // There is more than one way of doing this so different is not necessarily wrong.
8
9 #include <stdio.h>
10
11 int main(void)
12 {
13   const int level1 = 30;               // Quantity over this level are at discount1
14   const int level2 = 50;               // Quantity over this level are at discount2
15   const double discount1 = 0.10;       // 10% discount
16   const double discount2 = 0.15;       // 15% discount
17   const double unit_price = 5.0;       // Basic unit price
18   int quantity = 0;
19   int qty_full_price = 0;              // 0 to 30 at full price
20   int qty_level1 = 0;                  // 31 to 50 at level1 price
21   int qty_level2 = 0;                  // Over 50 at level2 price
22   printf("Enter the quantity that you require: ");
23   scanf("%d", &quantity);
24
25   if(quantity > 50)                     // Quantity over 50
26   {
27     qty_full_price = level1;
28     qty_level1 = level2 - level1;
29     qty_level2 = quantity - level2;
30   }
31   else if(quantity > 30)                // Quantity is from 30 to 50
32   {
33     qty_full_price = level1;
34     qty_level1 = quantity - level1;
35   }
36   else
37     qty_full_price = quantity;
38
39   printf("The total price for %d items is \$%.2lf
", quantity,
40     unit_price*(qty_full_price + (1.0 - discount1)*qty_level1 + (1.0 - discount2)*qty_level2));
41   return 0;
42 }```
• 相关阅读:
Web Api：基于RESTful标准
C#：导入Excel通用类（Xls格式）
C#：导入Excel通用类（Xlsx格式）
Selenium---Python3---下拉框选择处理
Selenium---Python3---弹框处理
Selenium---设置等待时间
Selenium---Python3--获取网页url/获取网页title
Selenium---键盘事件---Python3
Selenium---鼠标事件---Python3
Selenium---Python3---常见方法
• 原文地址：https://www.cnblogs.com/xiaomi5320/p/4170586.html
Copyright © 2011-2022 走看看