Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include int main(void) { float purchase_amount, discount, tax, final_total; char spirit_wear; // Prompt user for purchase amount printf(Enter the purchase amount> ); scanf(%f, &purchase_amount); fflush(stdin);

#include int main(void) { float purchase_amount, discount, tax, final_total; char spirit_wear; // Prompt user for purchase amount printf("Enter the purchase amount> "); scanf("%f", &purchase_amount); fflush(stdin); // Prompt user for Spirit Wear printf("Does this purchase include Spirit Wear (Y/N) ?> "); scanf("%c", &spirit_wear); fflush(stdin); // Check if Spirit Wear is included and apply discount if necessary if (spirit_wear == 'Y' || spirit_wear == 'y' ) { if (purchase_amount >= 100) { discount = purchase_amount * 0.10; printf("Purchase amount $%.2f ", purchase_amount); printf("Discount (10%%) $%.2f ", discount); } else { discount = purchase_amount * 0.07; printf("Purchase amount $%.2f ", purchase_amount); printf("Discount (7%%) $%.2f ", discount); } purchase_amount -= discount; printf("Purchase amount after discount $%.2f ", purchase_amount); } else if (spirit_wear == 'N'|| spirit_wear == 'n') { // No discount applied printf("Purchase amount $%.2f ", purchase_amount); } else { // Error message for invalid input printf("Invalid input. Please enter Y or N. "); return 0; } // Calculate and display sales tax tax = purchase_amount * 0.05; printf("Sales tax (5%%) $%.2f ", tax); // Calculate and display final total final_total = purchase_amount + tax; printf("Total purchase $%.2f ", final_total); return 0;}
image text in transcribedimage text in transcribedimage text in transcribed
In this assignment, you will practice: - Refactoring (restructuring) existing code a Implementing programmer-defined functions with inputs and return values Requirements This version of the program will appear exactly the same to the user, with the same prompts and outputs. The only difference is how the code is arranged. You must use the same selection structure that you used for the week 03 homework. Refer to the instructions for week 03 homework for the overall idea of what this project is about. Remember to use fflush(stdin) where appropriate. Requirements for Computing the Dollar Amount of the Discount The logic to compute the dollar amount of the discount must be located in a function with the following requirements: Function name: computeDiscount Parameters: purchase amount (double/float), discount rate (double/float) Return value: dollar amount of discount (double/float) Note that this function will not be called if the purchase does not include spirit wear. Requirements for Computing the New Purchase Amount The logic to compute the new purchase amount (the original purchase amount minus the discount amount) must be located in a function with the following requirements: Function name: computePurchase Parameters: dollar amount of discount, original purchase amount (both double/float) Return value: new purchase amount (double/float) Note that this function will not be called if the purchase does not include spirit wear. Requirements for Computing the Tax Amount The logic to compute the amount of tax must be located in a function with the following requirements: Function name: computeTax Parameter: new purchase amount (double/float) Return value: amount of tax (double/float) If the purchase does not include spirit wear, use the original purchase amount in place of the new purchase amount. Requirements for Computing the Final Total Purchase Amount The logic to compute the final purchase amount, including tax, must be located in a function with the following requirements: Function name: computeTotalPurchaseAmount Parameters: new purchase amount (double/float), amount of tax (double/float) Return value: total (double/float) If the purchase does not include spirit wear, use the original purchase amount in place of the new purchase amount. Output Requirements The results must line up at the decimal point, as displayed in the sample runs. Sample Run 1 Enter the purchase amount> 50.00 Does this purchase include Spirit Wear (Y/N)?> N Purchase amount $ 50.00 Sales tax (5%) Total purchase $ 52.50 {D N \"I COMPLETE AND ACCURATE Your program must compile, execute, and give accurate output. FOLLOW ALL REQUIREMENTS ACCORDING TO THE INSTRUCTIONS Follow the instructions as written for completing this project, even if you [think you] know a \"better" way to do something. COMMENTS Include comments in your code. There must be a comment at the top of your program that includes your name, the program number, and a description of the program. There must be comments at each important step in your program that describes that step. Every variable must include a comment describing its purpose

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What were the strengths and weaknesses in an oral presentation ?

Answered: 1 week ago