Mega Code Archive

 
Categories / C / Language Basics
 

Using ifs to decide on a discount

#include <stdio.h> void main() {   const double price = 3.50;                /* price*/      int quantity = 0;      printf("Enter the number that you want to buy:");     /* Prompt message */      scanf(" %d", &quantity);                             /* Read the input */    /* Test for order quantity qualifying for a discount */    if( quantity>20)                                     /* 5% discount */                          printf("The price for %d is $%.2f\n", quantity, quantity * price * 0.95);           else                                                     /* No discount */      printf("The price for %d is $%.2f\n", quantity, quantity * price);  }