码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 2.3 Calculating volume price of alternative products

时间:2014-12-16 22:34:36      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   io   color   os   sp   for   on   

// 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\n", quantity, type, total_price);
  return 0;
}

Most important :
total_price = quantity*(type1_price + (type - 1)*(type2_price - type1_price));

Exercise 2.3 Calculating volume price of alternative products

标签:style   blog   ar   io   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/xiaomi5320/p/4168165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!