Creating Functions (Modular Programming)

I have several errors, but i do not know what i generally did wrong??

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
 #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;
}
Last edited on
Start by reading the errors
I know, i tried fixing them and it is still not running...
closed account (48T7M4Gy)
float calculateStateTax (float purchaseAmount);
what is wrong with that line?
closed account (48T7M4Gy)
There's nothing wrong with it. Line 5 etc should look like it. ie no '='.
putting all in main.cpp is not modular programming.

Next thing , if you want to get real fast answer , start by providing all errors output , so we dont need to open a compiler to test your code and check these errors by ourselves .

Thanks.
i do not know what i generally did wrong?


Ok, what i'm doing is trying help you answer the above question.
IMO, you wrote too much code, don't know how to read your errors to fix it and now your looking for someone else to fix too many errors.

What I suggest is you start over, don't try and fix everything at once, start small, write a few lines of code that go together, like a section, function, headers and see what if any errors you get. Fix those them move on.

There are plenty of errors right here, nothing will work if this doesn't.

I do like the way you added comments, so I see hope for you. But you need to learn to fix your own mess. The best way is to not let it get so big before you try and fix it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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

{

	//End of Program
	return 0;
}
closed account (48T7M4Gy)
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;
}
Topic archived. No new replies allowed.