Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This program prompts the user to enter whether they are a teacher or non-teacher.
- * Once determined, the program prompts you to enter a purchase total.
- * Depending on whether the purchase is under $100 (10% discount)
- * or over $100 (12% discount) it will calculate the discount.
- * This discount is only applicable to teachers.
- * This discount is taken out before the addition of the 5% sales tax.
- * The program will then print out a receipt. */
- #include <stdio.h> /* printf, scanf difinition */
- #define SALES_TAX .05 /* defines sales tax as 5% */
- #define DISCOUNT_LOW .10 /* defines discount as 10% if purchase is $100 or less */
- #define DISCOUNT_HIGH .12 /* defines discount as 12% if purchase is more than $100 */
- #define DISCOUNT_LIMIT .100 /* defines the limit between discount percentages */
- int main(void)
- {
- double purchase_total;
- double discount;
- double discounted_total;
- double sales_tax;
- double total;
- int teacher;
- /* request inputs */
- printf("Is the customer a teacher (Y/N)? ");
- scanf("%c", &teacher);
- printf("Enter total purchases ");
- scanf("%lf", &purchase_total);
- /* calculations for teacher */
- if (teacher == 'Y')
- {/*calculate discount (10% or 12%) and 5% sales tax */
- /* purchase total less than 100 */
- if (purchase_total < 100)
- {
- /* calculate 10% discount */
- discount = purchase_total * DISCOUNT_LOW;
- discounted_total = purchase_total - discount;
- }
- /*purchase total greater than 100 */
- else
- { /* calculate 12% discount */
- discount = purchase_total * DISCOUNT_HIGH;
- discounted_total = purchase_total - discount;
- }
- printf("\nTotal purchases $%.2f ", purchase_total);
- printf("\nTeacher's discount %.2f ", discount);
- printf("\nDiscounted total %.2f ", discounted_total);
- printf("\nSales tax (5%%) %.2f ", sales_tax);
- printf("\nTotal $%.2f\n ", total);
- }
- /* calculation for nonteacher */
- if (teacher == 'N')
- {
- /* calculate only 5% sales tax */
- sales_tax = purchase_total * SALES_TAX;
- total = purchase_total + sales_tax;
- printf("\nTotal purchases $%.2f", purchase_total);
- printf("\nSales tax (5%%) %.2f", sales_tax);
- printf("\nTotal $%.2f", total);
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement