We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

copyleft on 12/08/07


Tagged

level Discount


Versions (?)


Discount levels


Published in: C++ 


  1. /* Program 3.6 Multiple discount levels */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void){
  6. const double unit_price = 3.50;
  7. const double discount1 = 0.05;
  8. const double discount2 = 0.1;
  9. const double discount3 = 0.15;
  10. double total_price = 0.0;
  11. int quantity = 0;
  12.  
  13. printf("Enter the number that you want to buy:");
  14. scanf(" %d", &quantity);
  15.  
  16. total_price = quantity+unit_price*(1.0 - (quantity>50 ? discount3 : (quantity>20 ? discount2 :( quantity>10 ? discount1 : 0.0))));
  17.  
  18.  
  19. printf("The price for %d is $%.2f\n", quantity, total_price);
  20. return 0;
  21. }

Report this snippet 

You need to login to post a comment.