Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include<stdio.h>
- //float price, tax, appleCareCharge, subtotal, total; // used float to store decimals
- float computeAppleCareCharges(int y, float p);
- float computeAppleSubtotal(float c, float p);
- float computeTax(float s);
- float computeTotalCharges(float s, float t);
- int main (void)
- {
- //variable declorations
- int years;
- char brand;
- float price = 0.0,
- subtotal = 0.0,
- tax = 0.0,
- total = 0.0;
- printf("Enter the price of the phone: "); //prompt user for price
- scanf("%f", &price); // assigns price a value
- scanf("%c", &brand); // remove new line
- printf("Is the phone an iPhone (Y/N)? "); //prompts on brand of phone
- scanf("%c", &brand); //store case variable "brand"
- switch (brand) //switch to choose answer to brand
- {
- case 'Y':
- case 'y':
- {
- printf("Enter the number of years of AppleCare: "); // get applecare variable
- scanf("%i", &years);
- float charge = computeAppleCareCharges(years, price);
- subtotal = computeAppleSubtotal(charge, price);
- tax = computeTax(subtotal);
- total = computeTotalCharges(subtotal, tax);
- printf("\nPrice of the phone: $%.2f\nAppleCare price: $%.2f\nSubtotal: $%.2f\nTax (5%%): $%.2f\nTotal Price: $%.2f",price, charge, subtotal, tax, total);
- break;
- }
- case 'N':
- case 'n':
- {
- tax = computeTax(price);
- total = computeTotalCharges(price, tax);
- printf("\nPrice of the phone: $%.2f \nThe tax is: $%.2f \nThe Total is: $%.2f",price,tax,total);
- break;
- }
- }
- return (0); // All C programs need this at the end of main
- }
- float computeAppleCareCharges(int years, float price)
- {
- float appleCareCharge = 0.0;
- if (years == 1 )
- appleCareCharge = (price * .12); //code included to compute variables and totals for iPhone w/ 1 year AppleCare, and display results
- else {
- if (years > 1) //code included to compute variables and totals for iPhone w/ >1 year AppleCare, and display results
- appleCareCharge = (price * .1) * years;
- else
- printf("You must have at least one year of AppleCare, please start again.");
- }
- return appleCareCharge;
- }
- float computeAppleSubtotal(float appleCareCharge, float price)
- {
- float subtotal = appleCareCharge + price;
- return subtotal;
- }
- float computeTax(float subtotal)
- {
- return (subtotal * .5);
- }
- float computeTotalCharges(float subtotal, float tax)
- {
- return (subtotal + tax);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement