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

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

转载于:https://www.cnblogs.com/xiaomi5320/p/4168165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值