function problem

My program will not build and run properly. I have an error saying box is too large for the statement. How would I fix this?


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
  #include <iostream>
#include <iomanip>
using namespace std;

double box(int vol, double surarea); //Function Declaration goes here


int main(void)
{
	double width, len, ht, volume, surfacearea;

	cout << "Enter width, len, ht: ";
	cin >> width >> len >> ht;

	box( width, len, ht, volume, surfacearea);

	cout << fixed << setprecision(3);
	cout << "Volume is " << volume << " surface area is " << surfacearea << endl;

	return 0;
}


double box(int vol, double surarea);//First line of the function goes here
{
	vol = width * len * ht;
	surarea = 2 * width * len + 2 * width * ht + 2 * len * ht;
}

The box function is declared and defined to take two arguments.

double box(int vol, double surarea); //Function Declaration goes here

double box(int vol, double surarea);//First line of the function goes here

But when it's called on line 15, 5 arguments are sent.
box( width, len, ht, volume, surfacearea);

The number of arguments needs to match.
In addition to the number of arguments not matching you also have the function as a double yet you don't have it returning anything. There is also no semicolon at the end of double box(int vol, double surarea);

Your code would look something like

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
#include <iostream>
#include <iomanip>
using namespace std;

void box(const double width, const double len, const double ht, double &volume, double &surfacearea);


int main(void)
{
	double width, len, ht, volume, surfacearea;

	cout << "Enter width, len, ht: ";
	cin >> width >> len >> ht;

	box(width, len, ht, volume, surfacearea);

	cout << fixed << setprecision(3);
	cout << "Volume is " << volume << " surface area is " << surfacearea << endl;

	return 0;
}


void box(const double width, const double len, const double ht, double &volume, double &surfacearea)
{
	volume = width * len * ht;
	surfacearea = 2 * width * len + 2 * width * ht + 2 * len * ht;
}
Topic archived. No new replies allowed.