my program compiles but does not run properly, please help!

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
#include <iostream>

using namespace std;

// Function name: get_data
// Purpose: Finding perimeter, volume, area of a room
//	Input(s):
// Output(s): perimeter, volume, area

void get_data(float& perimeter, float& volume, float& area, float& length, float& width, float&height);

// Function name: Calculation
// Purpose: To find the perimeter, volume, and area of the room
// Input(s): length, width, height
// Output(s): perimeter, volume, area

void calculation(float perimeter, float volume, float area, float length, float width, float height);

// Function name: Output
// Purpose: Display perimeter, volume, and area of a room
// Input(s): perimeter, volume, area, length, width, height
// Output(s):

void output(float perimeter, float volume, float area, float length, float width, float height);




int main()

{
    float perimeter, volume, area, length, width, height;
    
    get_data(perimeter, volume, area, length, width, height);
    
    calculation(perimeter, volume, area, length, width, height);
    
    output(perimeter, volume, area, length, width, height);
    
    system("pause");
    
    return 0;
}

void get_data(float& perimeter, float& volume, float& area, float& length,float& width, float& height)
{
    // user input section
    cout << "Press return after entering a number" << endl;
    cout << "Please enter the length of the room" << endl;
    cin >> length;
    
    cout << "Please enter the width of the room" << endl;
    cin >> width;
    
    cout << "Please enter the height of the room" << endl;
    cin >> height;
}


void calculation(float perimeter, float volume, float area, float length, float width, float height)
{
    // calculation section
    perimeter = (height * 2) + (width * 2);
    volume = length * width * height;
    area = length * width;
}


void output(float perimeter, float volume, float area, float length, float width, float height)
{
    // output section
    cout << "the perimeter is " << perimeter << " meters" << endl;
    cout << "the volume is " << volume << " cu. meters" << endl;
    cout << "the area is " << area << " sq. meters" << endl;
}

The answer I get are not correct.

Press return after entering a number
Please enter the length of the room
2
Please enter the width of the room
2
Please enter the height of the room
4


These are the answers it gives me

the perimeter is 2.76792e+19 meters
the volume is 4.59163e-41 cu. meters
the area is 2.76655e+19 sq. meters
sh: pause: command not found
Program ended with exit code: 0
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

You have unused parameters in several functions.
1
2
3
4
5
6
7
8
9
10
11
12
13
void get_data(float& perimeter, float& volume, float& area, float& length,float& width, float& height)
{
    // user input section
    cout << "Press return after entering a number" << endl;
    cout << "Please enter the length of the room" << endl;
    cin >> length;

    cout << "Please enter the width of the room" << endl;
    cin >> width;

    cout << "Please enter the height of the room" << endl;
    cin >> height;
}


perimeter, volume and area are passed by value. Thus, the original value is retained. As you have not initialised these variables, you will end up with "junk" values, usually resulting in huge positive or negative numbers, as shown by your output.
1
2
3
4
5
6
7
void calculation(float perimeter, float volume, float area, float length, float width, float height)
{
    // calculation section
    perimeter = (height * 2) + (width * 2);
    volume = length * width * height;
    area = length * width;
}
I'd also double check the calculation for perimeter. If you want to measure around the floor, the calculation wouldn't use the height of the room.
Please remove your other post (probably made by mistake)

http://www.cplusplus.com/forum/general/198621/
I was able to get my program to run properly, thanks for your help!
Topic archived. No new replies allowed.