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;
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.
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.