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
|
#include <iostream>
using namespace std;
//function declarations
float getPurchaseAmount();
float calculateStateTax(float );
float calculateCountyTax(float );
float calculateTotalSalesTax(float , float );
float calculateTotalSale(float , float );
void showResult(float , float , float , float );
//Declare constants
const float STATE_RATE = 0.04;
const float COUNTY_RATE = 0.02;
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)
{
//Calculate total sales tax
float totalSalesTax = stateTax + countyTax;
// return result
return totalSalesTax;
}
// Function to calculate total sale
float calculateTotalSale(float totalSalesTax, float purchaseAmount)
{
//Calculate total sale
float totalSale = totalSalesTax + purchaseAmount;
// return result
return totalSale;
}
void showResult(float purchaseAmount, float stateTax, float countyTax, float totalSalesTax)
{
//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 = " << purchaseAmount+stateTax+countyTax+totalSalesTax << endl;
}
|