Help with a shopping cart

Now I'm still in the beginning stages but I'm just testing out my first 2 functions and I am getting alot of errors on all my dim's... that says redefinition of formal parameter total, tax, taxTotal, etc. Im fairly new to functions what am I doing wrong here?

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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;
double itemValue(double item1, int quantity, double total);
double salesTax(double tax, double total, double totalTax);




int main()
{

	double item1 = 4.75;
		
	double itemValue(double item1, int quantity, double total);
	double salesTax(double tax, double total, double totalTax);



}
double itemValue(double item1, int quantity, double total)
{
	
	int quantity;
	double total;

	cout << "Thanks for shopping with us today, how many boxes of cereal were you looking to get? " << endl;
	cin >> quantity;
	total = quantity * item1;

	return total;

	}

double salesTax(double tax, double total, double totalTax)
{
	double tax = 0.05;
	double total;
	double totalTax;

	cout << "We are applying the standard 5 percent tax to your purchase.";

	totalTax = total * tax;

	return totalTax;

	cout << "The total price after tax is " << "$ " << totalTax << "." << endl;
}
I was just trying to test out what I had so far to see if it was working and lots of redefinition of formal parameter errors
The link goes over functions in C++.

EDIT: I apologize; I thought I posted the link: http://www.cplusplus.com/doc/tutorial/functions/

Nevertheless, it seems you figured it out. Awesome!
Last edited on
what do you mean?
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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;
double itemValue(double item1, int quantity, double total);
double salesTax(double tax, double totalTax, double total);




int main()
{
	const double tax  = 0.05;
	double itemValue(double item1, int quantity, double total);
	double salesTax(double tax, double totalTax, double total);


	system("pause");
		



}
double itemValue(double item1, int quantity, double total)
{
	cout << "Thanks for shopping with us today, how many boxes of cereal were you looking to get? " << endl;
	cin >> quantity;
	total = quantity * item1;

	return total;

	}

double salesTax(double tax, double totalTax, double total)
{
	
	

	cout << "We are applying the standard 5 percent tax to your purchase.";

	totalTax = total * tax;

	return totalTax;
	
}


i fixed the parameter issues, but not it's not displaying any information when I run it
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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;
double itemValue(double item1, int quantity, double total);
double salesTax(double tax, double totalTax, double total);
double item1 = 4.75;
const double tax = 0.05;
int quantity;



int main()
{
	double item1 = 0;
	int quantity = 0;
	double total = 0;
	double tax = 0;
	double totalTax = 0;


	cout << "Thanks for shopping with us today, how many boxes of cereal were you looking to get? " << endl;
	cin >> quantity;
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	cout << "The price before tax is $ " << itemValue(item1, quantity, total) << " ." << endl;
	
	cout << "\n The total price after tax is $ " << salesTax(tax, totalTax, total) << endl;


	system("pause");
		
	return 0;


}
double itemValue(double item1, int quantity, double total)
{
	item1 = 4.25;
	total = quantity * item1;

	return total;

	}

double salesTax(double tax, double totalTax, double total)
{
	
	tax = 0.05;

	cout << "We are applying the standard 5 percent tax to your purchase.";

	totalTax = itemValue(item1, quantity, total) * tax;

	return totalTax;
	
}


So I have the first function working correctly but it will not display the total after the tax is applied, what am I doing wrong in the salesTax function?
Please see my response in your other thread:
http://www.cplusplus.com/forum/general/249952/
Topic archived. No new replies allowed.