Inactive Tutor answered 07/21/22
Tutor
New to Wyzant
Here's the code:
using namespace std;
int main() {
// Variables for our input
int doorLength;
int doorWidth;
int windowLength;
int windowWidth;
int roomLength;
int roomWidth;
int roomHeight;
int areaPerGallon;
// Ask for values
cout << "What is the length of the door in feet? ";
cin >> doorLength;
cout << "What is the width of the door in feet? ";
cin >> doorWidth;
cout << "What is the length of the window in feet? ";
cin >> windowLength;
cout << "What is the width of the window in feet? ";
cin >> windowWidth;
cout << "What is the length of the room in feet? ";
cin >> roomLength;
cout << "What is the width of the room in feet? ";
cin >> roomWidth;
cout << "What is the height of the room in feet? ";
cin >> roomHeight;
cout << "What is the area that can be painted with on gallon of paint? ";
cin >> areaPerGallon;
// The paintable area is the four walls minus one door and two windows
int paintableArea = 2 * roomWidth * roomHeight + 2 * roomLength * roomHeight - doorLength * doorWidth - 2 * windowLength * windowWidth;
// Calculate gallons needed
double gallonsNeeded = (double)paintableArea / areaPerGallon;
cout << "You need " << gallonsNeeded << " gallons of paint." << endl;
return 0;
}
And it's output:
> ./main
What is the length of the door in feet? 7
What is the width of the door in feet? 3
What is the length of the window in feet? 4
What is the width of the window in feet? 5
What is the length of the room in feet? 10
What is the width of the room in feet? 15
What is the height of the room in feet? 9
What is the area that can be painted with on gallon of paint? 120
You need 3.24167 gallons of paint.