1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
using namespace std;
//function declarations
float getPurchaseAmount();
float calculateStateTax (float purchaseAmount);
float calculateCountyTax (float purchaseAmount);
float calculateTotalSalesTax (float stateTax, float countyTax);
float calculateTotalSale (float totalSalesTax, float purchaseAmount);
void showResult (float purchaseAmount, float stateTax, float countyTax, float totalSalesTax);
//Declare constants
const float STATE_RATE = 0.04f;
const float COUNTY_RATE = 0.02f;
int main() // start of the main function
{
//Declare and initialize variables
float purchaseAmount = 0;
float stateTax = 0;
float countyTax = 0;
float totalSalesTax = 0;
float totalSale = 0;
// Get PurchaseAmount
purchaseAmount = getPurchaseAmount();
//Get State Tax
stateTax= calculateStateTax (purchaseAmount);
//Get County Tax
countyTax = calculateCountyTax (purchaseAmount);
// Get total Sales tax
totalSalesTax = calculateTotalSalesTax(stateTax, countyTax);
// Get total sale
totalSale = calculateTotalSale(totalSalesTax, purchaseAmount);
// Display results
showResult(purchaseAmount,stateTax, countyTax,totalSalesTax);
char quitKey;
//Delay
cout << "Press any key and Enter to end program: ";
cin >> quitKey;
//End of Program
return 0;
}
//Function to display purchase amount
float getPurchaseAmount()
{
float purchaseAmount;
cout << "Enter the amount of purchase and press ENTER" << endl;
cin >> purchaseAmount;
//return result
return purchaseAmount;
}
// Function to Calculate state tax
float calculateStateTax(float purchaseAmount)
{
//Decxlare variables for state tax
float stateTax;
//Calculate State tax
stateTax = STATE_RATE * purchaseAmount;
//return result
return stateTax;
}
//Function to Calculate County tax
float calculateCountyTax(float purchaseAmount)
{
//Declare variables for county tax
float countyTax;
//Calculate County tax
countyTax = COUNTY_RATE * purchaseAmount;
//return result
return countyTax;
}
//Function to calculate total sales tax
float calculateTotalSalesTax(float stateTax, float countyTax)
{
float totalSalesTax;
//Calculate total sales tax
totalSalesTax = stateTax + countyTax;
// return result
return totalSalesTax;
}
// Function to calculate total sale
float calculateTotalSale(float totalSalesTax, float purchaseAmount)
{
float totalSale;
//Calculate total sale
totalSale = totalSalesTax + purchaseAmount;
// return result
return totalSale;
}
void showResult(float purchaseAmount, float stateTax, float countyTax, float totalSalesTax,float totalSale)
{
//Display all the purchase amount, state tax, county tax, total tax, and total of sale
cout << "Purchase amount = " << purchaseAmount << endl;
cout << "State tax = " << stateTax << endl;
cout << "County tax = " << countyTax << endl;
cout << "Total tax = " << totalSalesTax << endl;
cout << "Total of sale = " << totalSale << endl;
}
|