Creating Functions (Modular Programming)

I have several errors, but i do not know where i generally messed up?

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
  #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.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 = (float purchaseAmount);
	
	//Get County Tax
	countyTax = calculateCountyTax = (float purchaseAmount);

	// Get total Sales tax
	totalSalesTax = calculateTotalSalesTax = (float stateTax, float countyTax);

	// Get total sale  
	totalSale = calculateTotalSale = (float totalSalesTax, float purchaseAmount);

	// Display results
	showResult(float purchaseAmount, float stateTax, float countyTax, float 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 >> purchase;
	//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
	totalSalesTax = stateTax + countyTax;
	// return result
	return totalSalesTax
}
// Function to calculate total sale
float calculateTotalSale(float totalSalesTax, float purchaseAmount)
{
	//Calculate total sale
	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 = " << totalSale << endl;
}
You are redeclaring new variables with old names in your function calls.

Declare a variable,
float nameVar;

Initialize variable, (first time only)
nameVar = 0;

Declare and initialize at same time,
float nameVar = 0;

To use it in a function you simply use the name,
functionCall(nameVar);
Last edited on
Topic archived. No new replies allowed.