⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex2_03.c

📁 [C语言入门经典(第4版)]整本书的源码!值得推荐!全部是最简单的源码!
💻 C
字号:
/* 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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -