Write a program that wil compute the volume of a room. User inputs are the height,width and length of each room. You have to declare 3 functions.
a)one for input
b)one to do the calculation,and
c)one for output
The input function has to input the height,width and length into the variables theHeight,theLength,theWidth. all 3 are of type int. As the values of them wil change in this function reference parameters need to be used.
The calculation function wil receive three parameters the represent the height, width and length do calculation and return the volume of the room.As the parameters are not changed in the function, they should be value parameters. The function should return an int value which represents the volume.
Output function has to display the height, width and length entered by the user as well as the volume. you also have to indicate the size of the room as small,medium,large. If the volume is less than 100 the volume is small,between 100 and 500 the size is medium and greater than 500 the size is large.
For example:
The volume of a room with height 3, width 4 and length 5 is 60.
Size: Small
The main function includes a for loop that allows the user to repeat the calculation of the volume for new input values five times.
//This code was made completely by -TheNewKid- Please do not take credit for this code.
#include <iostream>
usingnamespace std;
int main ()
{
int height = 0;
int length = 0;
int width = 0;
int volume = 0;
cout << "Welcome to the room volume calculator created by -TheNewKid-!" << endl << endl;
cout << "Please enter the height of your room: ";
cin >> height;
cout << endl << "Please enter the width of your room: ";
cin >> width;
cout << endl << "Please enter the length of your room: ";
cin >> length;
cout << endl << "Thank you for your input." << endl;
volume = height * length * width;
cout << "The volume of your room with width " << width << ", height " << height <<", and length " << length << " is " << volume << "." << endl;
if (volume < 100) {
cout << "Size: small" << endl;
}
elseif (volume > 100 && volume < 500) {
cout << "Size: medium" << endl;
}
else {
cout << "Size: large" << endl;
}
cout << endl << endl << "Thank you for using -TheNewKids- room volume calculator.";
cout << endl << endl << "---end of program---" << endl << endl;
return 0;
}
If you want something that loops 5 times, you can do it like this. You've got all the information you need already to write the functions getData and displayOutput
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main( )
{
int theHeight;
int theWidth;
int thelength;
int theVolume;
for (int i = 0; i < 5; i++)
{
getData(theHeight, theWidth,theLength);
displayOutput(theHeight, theWidth, theLength);
}
return 0;
}