Advertisement
conception

program 3

Feb 6th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. /* This program prompts the user to enter whether they are a teacher or non-teacher.
  2. * Once determined, the program prompts you to enter a purchase total.
  3. * Depending on whether the purchase is under $100 (10% discount)
  4. * or over $100 (12% discount) it will calculate the discount.
  5. * This discount is only applicable to teachers.
  6. * This discount is taken out before the addition of the 5% sales tax.
  7. * The program will then print out a receipt. */
  8.  
  9. #include <stdio.h> /* printf, scanf difinition */
  10. #define SALES_TAX .05 /* defines sales tax as 5% */
  11. #define DISCOUNT_LOW .10 /* defines discount as 10% if purchase is $100 or less */
  12. #define DISCOUNT_HIGH .12 /* defines discount as 12% if purchase is more than $100 */
  13. #define DISCOUNT_LIMIT .100 /* defines the limit between discount percentages */
  14.  
  15. int main(void)
  16. {
  17. double purchase_total;
  18. double discount;
  19. double discounted_total;
  20. double sales_tax;
  21. double total;
  22. int teacher;
  23.  
  24. /* request inputs */
  25. printf("Is the customer a teacher (Y/N)? ");
  26. scanf("%c", &teacher);
  27. printf("Enter total purchases ");
  28. scanf("%lf", &purchase_total);
  29.  
  30. /* calculations for teacher */
  31. if (teacher == 'Y')
  32. {/*calculate discount (10% or 12%) and 5% sales tax */
  33. /* purchase total less than 100 */
  34. if (purchase_total < 100)
  35. {
  36. /* calculate 10% discount */
  37. discount = purchase_total * DISCOUNT_LOW;
  38. discounted_total = purchase_total - discount;
  39. }
  40.  
  41. /*purchase total greater than 100 */
  42. else
  43. { /* calculate 12% discount */
  44. discount = purchase_total * DISCOUNT_HIGH;
  45. discounted_total = purchase_total - discount;
  46. }
  47.  
  48. printf("\nTotal purchases $%.2f ", purchase_total);
  49. printf("\nTeacher's discount %.2f ", discount);
  50. printf("\nDiscounted total %.2f ", discounted_total);
  51. printf("\nSales tax (5%%) %.2f ", sales_tax);
  52. printf("\nTotal $%.2f\n ", total);
  53. }
  54.  
  55.  
  56. /* calculation for nonteacher */
  57. if (teacher == 'N')
  58. {
  59. /* calculate only 5% sales tax */
  60. sales_tax = purchase_total * SALES_TAX;
  61. total = purchase_total + sales_tax;
  62.  
  63. printf("\nTotal purchases $%.2f", purchase_total);
  64. printf("\nSales tax (5%%) %.2f", sales_tax);
  65. printf("\nTotal $%.2f", total);
  66. }
  67.  
  68. return(0);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement