C - Write program to calculate product price

Requirements

A product type 1 is a standard version priced at $3.50

type 2 is a deluxe version priced at $5.50.

Prompts for the user to enter the product type and a quantity.

Calculates and outputs the price for the quantity entered.

Demo

#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));

  printf("The price for %d of type %d is $%.2f\n", quantity, type, total_price);
  return 0;/*w ww.jav  a  2 s  .co  m*/
}

Result

Related Exercise