Please help with including a for loop in main function that allows the user to repeat the calculation of the volume for new input values five times. The program and functions are working correct without the loop.
This is what I have done but its not working correctly:
//program that will compute the volume of a room. User inputs are the height, width and length of a room.
#include <iostream>
#include <string>
using namespace std;
void getData (int & height, int & width, int & length);
int calculateVolume (int & height, int & width, int & length, int & volume);
void displayOutput (int & height, int & width, int & length, int & volume);
int main ()
{
int height, width, length, volume, size;
for (int i = 1; i >= 5; i++)
getData(height, width, length);
calculateVolume(height, width, length, volume);
displayOutput(height, width, length, volume);
return 0;
}
void getData (int & height, int & width, int & length)
{
cout << "Enter height, width and length of room:" <<endl;
cin >> height >> width >> length;
}
int calculateVolume (int & height, int & width, int & length, int & volume)
{
volume = height * width * length;
}
void displayOutput (int & height, int & width, int & length, int & volume)
{
string size;
if (volume < 100)
{
size = "small";
cout << "The volume of a room with height "<<height <<", width "<<width <<" and length "<<length << " is "<<volume <<"."<<endl;
cout << "size: " <<size;
}
else if (volume >= 100 && volume <= 500)
{
size = "medium";
cout << "The volume of a room with height "<<height <<", width "<<width <<" and length "<<length << " is "<<volume <<"."<<endl;
cout << "size: " <<size;
}
else
{
size = "large";
cout << "The volume of a room with height "<<height <<", width "<<width <<" and length "<<length << " is "<<volume <<"."<<endl;
cout << "size: " <<size;
}
}
You do already have a for loop in your main() that repeats the statements within its body according to the condition that you have set.
You should read carefully: http://www.cplusplus.com/doc/tutorial/control/
Enter height, width and length of room:
23
33
1
The volume of room with height 23, width 33 and length 1 is 759.
size: largeThe volume of room with height 23, width 33 and length 1 is 759.
size: large
process returned 0 <0x0> execution time