Ive been trying to do my homework for the past 2 hours and I can't seem to get the correct answer, I keep getting 5/6 answers correct. Please help!!
(1) Prompt the user to input a wall's height and width. Calculate and output the wall's area. (2 pts)
Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.
Enter wall height (feet):
12
Enter wall width (feet):
15
Wall area: 180 square feet
(2) Extend to also calculate and output the amount of paint in gallons needed to paint the wall. Assume a gallon of paint covers 350 square feet. Store this value using a const double variable. (2 pts)
Enter wall height (feet):
12
Enter wall width (feet):
15
Wall area: 180 square feet
Paint needed: 0.514286 gallons
(3) Extend to also calculate and output the number of 1 gallon cans needed to paint the wall. Hint: Use a math function to round up to the nearest gallon. (2 pts)
Enter wall height (feet):
12
Enter wall width (feet):
15
Wall area: 180 square feet
Paint needed: 0.514286 gallons
Cans needed: 1 can(s)
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
|
#include <iostream>
#include <cmath> // Note: Needed for math functions in part (3)
using namespace std;
int main() {
double wallHeight = 0.0;
double wallWidth = 0.0;
double wallArea = 0.0;
cout << "Enter wall height (feet):";
cin >> wallHeight;
cout << endl;
cout << "Enter wall width (feet):";
cin >> wallWidth;
cout << endl;
wallWidth = 15.0; // FIXME (1): Prompt user to input wall's width
// Calculate and output wall area
wallArea = wallHeight * wallWidth; // FIXME (1): Calculate the wall's area
cout << "Wall area: " << wallArea << " square feet" << endl; // FIXME (1): Finish the output statement
cout << "Paint needed: " << (wallArea / 350) << " gallons" << endl;// FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall
cout << "Cans needed: " <<round((wallArea/350))<< " can(s)" << endl; // FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer
return 0;
|
that is the question along with the code I inputed, I just need to fix #3
}
|
cout << "Cans needed: " << round((wallArea / 350)) << " can(s)" << endl;
|