zoukankan      html  css  js  c++  java
  • Exercise 2.3 Calculating volume price of alternative products

    // Exercise 2.3  Calculating volume price of alternative products
    
    // The only problem here is to devise a way to determine the price
    // for the product type. Here I used the product type value to do this.
    #include <stdio.h>
    
    int main(void)
    {
      double total_price = 0.0;                // Total price
      int type = 0;                            // Product type
      int quantity = 0;                        // Quantity ordered
      const double type1_price = 3.50;
      const double type2_price = 5.50;
    
      // Get the product type
      printf("Enter the type (1 or 2): ");
      scanf("%d", &type);
    
      // Get the order quantity
      printf("Enter the quantity: ");
      scanf("%d", &quantity);
    
      // Calculate the total price
      total_price = quantity*(type1_price + (type - 1)*(type2_price - type1_price));
    
      // Output the area
      printf("The price for %d of type %d is $%.2f
    ", quantity, type, total_price);
      return 0;
    }

    Most important :
    total_price = quantity*(type1_price + (type - 1)*(type2_price - type1_price));
  • 相关阅读:
    (九)分类展示上
    (八)用户退出
    (七)用户登陆
    opencord视频截图
    (六)电子邮件
    (五)密码加密
    (四)用户注册
    (三)首页处理
    this关键字在继承中的使用
    03.swoole学习笔记--web服务器
  • 原文地址:https://www.cnblogs.com/xiaomi5320/p/4168165.html
Copyright © 2011-2022 走看看