Custom Functions Problem

I'm just finishing my c++ course with functions and this program has me completely stumped. I don't know why it won't work. My "volume" variable on line 80 says it is undefined.


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
/*
PROGRAM DESCRIPTION
Input: Width, height, length, and rerun
Output: User instructions, width, length, height, area, and volume
*/
#include <iostream>
#include <iomanip>
using namespace std;

double Area(double length, double width, double height);

double Volume(double length, double width, double height);

void DisplayData(double length, double width, double height, double area, double volume);

void main()
{
	//variable declaration
	double width, length, height, area, volume;
	char repeat='y';

	//setprecision

	cout.setf(ios::fixed, ios::floatfield);
	cout.setf(ios::showpoint);
	cout<<setprecision(2);

	//user instructions
	cout<<"This program requires the length, width, and height of a box and prints"<<endl;
	cout<<"the box's length, width, height, area, and volume of that box."<<endl;
	cout<<"Please limit your dimensions to less than or equal to 99"<<endl;
	cout<<"If the dimensions are larger try converting it to a larger unit type"<<endl;
	cout<<"e.g 100 millimeters equals 10 centimeters so all your measurements would"<<endl;
	cout<<"be in centimeters"<<endl;

	do//do-while 
	{
		//intro input
		cout<<"Please enter the width of your box";
		cin>>width;
		cout<<"Please enter the length of your box";
		cin>>length;
		cout<<"Please enter the height of your box";
		cin>>height;

		//function calls and returns variables
		area=Area(length,width,height);
		volume=Volume(length,width,height);

		DisplayData(length,width,height,area,volume);

		//rerun the program
		cout<<"Enter y or Y to rerun the program, anything else to quit ";
		cin>>repeat;
	}while (repeat=='y'||repeat=='Y');//end do-while

}//end main

double Area(double length, double width, double height)
{
	/*
	This function receives the length, height, and width entered and calculates the area of the box

	Pre: none
	Post: returns to the area of the box
	*/
	double area;
	area=((length*height)+(length*width)+(width*height))*2;
	return area;
}
double Volume(double length, double width, double height)
{
	/*
	This function recieves the length, height, and width entered and calculates the volume of the box

	Pre: none
	Post: returns the volume of the box
	*/
	double volme;
	volume=length*width*height;
	return volume;
}

void DisplayData(double length, double width, double height, double area, double volume)
{
	/*
	This function displays the area and volume of the box.
	Pre: none
	post: displays data
	*/
	//set precision
	cout.setf(ios::fixed, ios::floatfield);
	cout.setf(ios::showpoint);
	cout<<setprecision(2);

	cout<<"The width of your box is "<<setw(21)<<width<<endl;
	cout<<"The length of your box is "<<setw(20)<<length<<endl;
	cout<<"The height of your box is "<<setw(20)<<height<<endl;
	cout<<"The area of your box is "<<setw(22)<<area<<endl;
	cout<<"The volume of your box is "<<setw(20)<<volume<<endl;
	system("pause");
}//end Displaydata 
Last edited on
You misspelled volume when you declared it. Although to save a variable since you don't use volume after that you could just do
 
return (length * width * height);

Last edited on
Thanks
Topic archived. No new replies allowed.