Room volume calculation program not running

Hi, im stuck on the last question for my assignment. Its to do with working out the volume of a room based on values that the user enters for the height, width and length of the room. The program is ment to make use of three functions, namely - getData(),calculateVol() and displayData(). The question also states that the main function should contain a for loop so that the program can be run up to five times. In the end my program isnt running at all and is giving me two warnings being "left hand operand of comma has no effect as well as the right on line 17" as well as an error - "expected initialiser before '<' token on line 60"

Here's my code:

#include <iostream>
using namespace std;

int getData(int theHeight,int theWidth,int theLength);
int calculateVolume(int theHeight,int theWidth,int theLength);
void displayOutput(int theHeight,int theWidth,int theLength);

int getData(int theHeight,int theWidth,int theLength)
{
cout << "Please enter the height of your room" << endl;
cin >>theHeight;
cout << "Please enter the width of your room" << endl;
cin >>theWidth;
cout << "Please enter the length of your room" << endl;
cin >>theLength;

return theHeight,theWidth,theLength;

}
int calculateVolume(int theHeight,int theWidth,int theLength)
{
int volume;

volume = theHeight*theWidth*theLength;

return volume;
}
void displayOutput(int theHeight,int theWidth,int theLength)
{
int volume;

cout << "The volume of a room with " << theHeight << ", width " << theWidth << " and length " << theLength << " is " << volume << endl;

if (volume < 100)
{
cout << "Size: small" << endl;
}
else

if (volume > 100 || volume < 500)
{
cout << "Size: medium" << endl;
}
else

if (volume > 500)
{
cout << "Size: large" << endl;
}

}
int main()
{
int theHeight;
int theWidth;
int theLength;

for (int i = 0, i < 5; i++;)
{
getData(theHeight,theWidth,theLength);
calculateVolume(theHeight,theWidth,theLength);
displayOutput(theHeight,theWidth,theLength);
}
return 0;
}
closed account (D80DSL3A)
About the comma warning:
return theHeight,theWidth,theLength; You can't return 3 values from a function.
Pass the 3 values by reference and they will be written to in the function.
Suggest:
void getData(int& theHeight,int& theWidth,int& theLength);
Simple mistake in the for loop causes an actual error:
for (int i = 0, i < 5; i++;)// syntax incorrect.
Right now after your specified changes, the program runs but i dont think its getting the inputed numbers correctly because no matter what number combination i use for height,width and length it always gives the volume as 4199363.

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

int getData(int & theHeight,int & theWidth,int & theLength);
int calculateVolume(int & theHeight,int & theWidth,int & theLength);
void displayOutput(int & theHeight,int & theWidth,int & theLength);

int getData(int & theHeight,int & theWidth,int & theLength)
{
    cout << "Please enter the height of your room" << endl;
    cin >>theHeight;
    cout << "Please enter the width of your room" << endl;
    cin >>theWidth;
    cout << "Please enter the length of your room" << endl;
    cin >>theLength;

    return 0;

}
int calculateVolume(int & theHeight,int & theWidth,int & theLength)
{
    int volume;

    volume = theHeight*theWidth*theLength;

    return volume;
}
void displayOutput(int & theHeight,int & theWidth,int & theLength)
{
    int volume;

    cout << "The volume of a room with height " << theHeight << ", width " << theWidth << " and length " << theLength << " is " << volume << endl;

    if (volume < 100)
    {
        cout << "Size: small" << endl;
    }
    else

    if (volume > 100 || volume < 500)
    {
        cout << "Size: medium" << endl;
    }
    else

    if (volume > 500)
    {
        cout << "Size: large" << endl;
    }

}


int main()
{
    int theHeight;
    int theWidth;
    int theLength;

    for (int i = 0; i < 5; i++)
    {
        getData(theHeight,theWidth,theLength);
        calculateVolume(theHeight,theWidth,theLength);
        displayOutput(theHeight,theWidth,theLength);

    }
    return 0;
}
closed account (D80DSL3A)
You're displaying the value of the uninitialized local variable named volume in the displayOutput() function.
The value for the volume was calculated then thrown away on line 63 where calculateVolume() is called.
Easy fix? Recalculate the volume in the displayOutput() function.
New line 30:
int volume = calculateVolume(theHeight,theWidth,theLength);

You will then discover issues with the if-else if-else if code.
Would it not be easier to initialize volume inside calculateVolume to 0 and remove the local variable inside displayOutput?
Topic archived. No new replies allowed.