I can't calculate the final result

These are my errors

https://41.media.tumblr.com/ee8447679e09e3f13cd22b590a158195/tumblr_nyv9maI5P41qdp21xo1_1280.png

I guess there's something wrong with the void Bestbuy at the end. Before I included those words inside the parenthesis, I ran the program and the results only showed 0 for the price, square per inch, area, etc. Any ideas? I'm assuming there's something wrong with my calculations

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
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.14;

void Size(double&, double&, double&);
void Price(double&, double&, double&);
double Radius(double&, double&, double&);
double Area(double&, double&, double&);
double Perinch(double&, double&, double&);
void Bestbuy(double, double, double, double, double, double, double, double, double);

int main()
{

	cout << "Hello, please enter the size and the price of the pizza you want." << endl;
	cout << " Small Pizza has to be between 5 to 7 inches " << endl;
	cout << " Medium pizza has to be between 8 to 10 inches " << endl;
	cout << " Large pizza has to be between 11 to 13 inches " << endl;
	cout << "\n";

	double smallsize,
		mediumsize,
		largesize,
		smallprice,
		mediumprice,
		largeprice,
		smallarea,
		mediumarea,
		largearea,
		smallinch,
		mediuminch,
		largeinch;
	Size(smallsize, mediumsize, largesize);
	Price(smallprice, mediumprice, largeprice);
	Bestbuy(smallsize, mediumsize, largesize, smallprice, mediumprice, largeprice);

	system("pause");
	return 0;
}
void Size(double&smallsize, double& mediumsize, double& largesize) {

	do {
		cout << "Small pizza Diameter (in inches) = " << endl;
		cin >> smallsize;
	} while (smallsize < 5 || smallsize > 7);

	do {
		cout << "Medium pizza Diameter (in inches) = " << endl;
		cin >> mediumsize;
	} while (mediumsize < 8 || mediumsize > 10);

	do {
		cout << "Large pizza Diameter (in inches) = " << endl;
		cin >> largesize;
	} while (largesize < 11 || largesize > 13);

}



void Price(double&smallprice, double&mediumprice, double&largeprice)
{


	cout << "Enter the price of the small pizza = $" << endl;
	cin >> smallprice;
	cout << "Enter the price of the medium pizza = $" << endl;
	cin >> mediumprice;
	cout << "Enter the price of the large pizza = $" << endl;
	cin >> largeprice;
}


double Radius(double&sradius, double&mradius, double&lradius, double&smallarea, double&mediumarea, double&largearea)
{
	double smallsize = 0.00,
		mediumsize = 0.00,
		largesize = 0.00;
	sradius = (smallsize / 2);
	mradius = (mediumsize / 2);
	lradius = (largesize / 2);
	return (sradius, mradius, lradius);
}

double Area(double&smallarea, double&mediumarea, double&largearea)
{
	double sradius = 0.00,
		mradius = 0.00,
		lradius = 0.00;

	smallarea = (PI * sradius) * 2;
	mediumarea = (PI * mradius) * 2;
	largearea = (PI * lradius) * 2;

	return (smallarea, mediumarea, largearea);
}


void Bestbuy(double smallarea, double mediumarea, double largearea, double smallprice, double mediumprice, double largeprice, double smallinch, double mediuminch, double largeinch) 
{

	double smallarea = 0.00,
		mediumarea = 0.00,
		largearea = 0.00,
		smallprice = 0.00,
		mediumprice = 0.00,
		largeprice = 0.00,
		smallinch = 0.00,
		mediuminch = 0.00,
		largeinch = 0.00;


	cout << "\n";
	cout << "\n";
	cout << fixed << setprecision(2);
	cout << " Small Pizza Diameter = " << smallarea << " inches" " Price = $" << smallprice << " Per square Inch = " << smallinch << endl;
	cout << "\n";
	cout << " Medium Pizza Diameter = " << mediumarea << " inches" " Price = $" << mediumprice << " Per square Inch = " << mediuminch << endl;
	cout << "\n";
	cout << " Large Pizza Diameter = " << largearea << " inches" " Price = $" << largeprice << " Per square Inch = " << largeinch << endl;
	cout << "\n";

}
I ran the program and the results only showed 0 for the price, square per inch, area, etc. Any ideas? I'm assuming there's something wrong with my calculations

At a very quick glance I don't see anything wrong with your calculations. However Please explain the following:
1
2
3
4
5
6
7
8
9
10
11
12
void Bestbuy(double smallarea, double mediumarea, double largearea, double smallprice, double mediumprice, double largeprice, double smallinch, double mediuminch, double largeinch) 
{

	double smallarea = 0.00,
		mediumarea = 0.00,
		largearea = 0.00,
		smallprice = 0.00,
		mediumprice = 0.00,
		largeprice = 0.00,
		smallinch = 0.00,
		mediuminch = 0.00,
		largeinch = 0.00;

Why are you passing values into this function then immediately hiding the values by creating new variables with the same names that are initialized to zero?


By the way your return statements inside your Radius and Area function are incorrect, you can only return one value with the return statement. However I don't see where you're actually using these functions so it probably doesn't matter much.
Oh you're right I shouldn't have done that. Thanks!

I cleaned up some parts and got a problem. Here it is:
http://40.media.tumblr.com/e48f2d12a145b9dcaab8db4b6509bd07/tumblr_nyvd17b6mo1qdp21xo1_1280.png

At the end result it can list out the prices the user input, but the diameter is 0.00 and the per square inch is inf. Any ideas?

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.14;

void Size(double&, double&, double&);
void Price(double&, double&, double&);
double Radius(double&, double&, double&, double&, double&, double&);
double Area(double&, double&, double&);
double Perinch(double&, double&, double&, double&, double&, double&);
void Bestbuy(double&, double&, double&, double&, double&, double&, double&, double&, double&);

int main()
{

	cout << "Hello, please enter the size and the price of the pizza you want." << endl;
	cout << " Small Pizza has to be between 5 to 7 inches " << endl;
	cout << " Medium pizza has to be between 8 to 10 inches " << endl;
	cout << " Large pizza has to be between 11 to 13 inches " << endl;
	cout << "\n";

	double smallsize,
		mediumsize,
		largesize,
		smallprice,
		mediumprice,
		largeprice,
		smallarea,
		mediumarea,
		largearea,
		smallinch,
		mediuminch,
		largeinch,
		sradius,
		mradius,
		lradius;
		
	Size(smallsize, mediumsize, largesize);
	Price(smallprice, mediumprice, largeprice);
	Radius(sradius, mradius, lradius, smallarea, mediumarea, largearea);
	Area(smallarea, mediumarea, largearea);
	Perinch(smallinch, mediuminch, largeinch, smallprice, mediumprice, largeprice);
	Bestbuy(smallarea, mediumarea, largearea, smallprice, mediumprice, largeprice, smallinch, mediuminch, largeinch);

	system("pause");
	return 0;
}
void Size(double&smallsize, double& mediumsize, double& largesize) {

	do {
		cout << "Small pizza Diameter (in inches) = " << endl;
		cin >> smallsize;
	} while (smallsize < 5 || smallsize > 7);

	do {
		cout << "Medium pizza Diameter (in inches) = " << endl;
		cin >> mediumsize;
	} while (mediumsize < 8 || mediumsize > 10);

	do {
		cout << "Large pizza Diameter (in inches) = " << endl;
		cin >> largesize;
	} while (largesize < 11 || largesize > 13);

}



void Price(double&smallprice, double&mediumprice, double&largeprice)
{


	cout << "Enter the price of the small pizza = $" << endl;
	cin >> smallprice;
	cout << "Enter the price of the medium pizza = $" << endl;
	cin >> mediumprice;
	cout << "Enter the price of the large pizza = $" << endl;
	cin >> largeprice;
}


double Radius(double&sradius, double&mradius, double&lradius, double&smallarea, double&mediumarea, double&largearea)
{
	double smallsize = 0.00,
		mediumsize = 0.00,
		largesize = 0.00;
	sradius = (smallsize / 2);
	mradius = (mediumsize / 2);
	lradius = (largesize / 2);
	return (sradius, mradius, lradius);
}

double Area(double&smallarea, double&mediumarea, double&largearea)
{
	double sradius = 0.00,
		mradius = 0.00,
		lradius = 0.00;

	smallarea = (PI * sradius) * 2;
	mediumarea = (PI * mradius) * 2;
	largearea = (PI * lradius) * 2;

	return (smallarea, mediumarea, largearea);
}

double Perinch(double&smallinch, double&mediuminch, double&largeinch, double&smallprice, double&mediumprice, double&largeprice)
{
	double smallarea = 0.00,
		mediumarea = 0.00,
		largearea = 0.00;

	smallinch = (smallprice / smallarea);
	mediuminch = (mediumprice / mediumarea);
	largeinch = (largeprice / largearea);

		return (smallinch, mediuminch, largeinch);
}


void Bestbuy(double&smallarea, double&mediumarea, double&largearea, double&smallprice, double&mediumprice, double&largeprice, double&smallinch, double&mediuminch, double&largeinch)
{

	cout << "\n";
	cout << "\n";
	cout << fixed << setprecision(2);
	cout << " The diameter of the small pizza is " << smallarea << " inches" " Price = $" << smallprice << " Per square Inch = " << smallinch << endl;
	cout << "\n";
	cout << " The diameter of the medium pizza is " << mediumarea << " inches" " Price = $" << mediumprice << " Per square Inch = " << mediuminch << endl;
	cout << "\n";
	cout << " The diameter of the large pizza is " << largearea << " inches" " Price = $" << largeprice << " Per square Inch = " << largeinch << endl;
	cout << "\n";

}
I suggest you start simplifying your functions, right now they are doing too much. For example:
1
2
3
4
5
6
7
8
9
10
double Radius(double&sradius, double&mradius, double&lradius, double&smallarea, double&mediumarea, double&largearea)
{
	double smallsize = 0.00,
		mediumsize = 0.00,
		largesize = 0.00;
	sradius = (smallsize / 2);   // This will always yield zero.
	mradius = (mediumsize / 2);
	lradius = (largesize / 2);
	return (sradius, mradius, lradius);  // This is wrong, you can only return one item.
}

Instead of trying to compute the radius of all the sizes at once set it up to do one calculation and then call it where ever it is needed.

Also this function is seriously flawed in several places. First you dividing zero by two, what will the result be? Next as I said in my last post you can only return one value in the return clause.

1
2
3
4
double radius(double diameter)
{
	return (diameter / 2.0);
}

Now call this function whenever you want to know the radius of the pizza. By the way I don't see where you're actually using the radius anywhere in your program. So this function is probably not affecting your output but you're making the same mistake several places in your program.
Topic archived. No new replies allowed.