This is C++
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)

Respuesta :

Answer:

#include <cmath>

#include<iostream>

using namespace std;

int main()

{

double height, width;

cout<<"Enter wall height (feet): ";

cin>>height;

cout<<"Enter wall width (feet):  ";

cin>>width;

//1

double area;

area = width * height;

cout<<"Wall area: "<<area<<" square feet"<<"\n";

//2

const double gallon = area/350.0;

cout<<"Paint needed: "<<gallon<<" gallons"<<"\n";

//3

cout << "Cans needed :" << round(gallon) << " can(s)";  

return 0;

}

Explanation:

This line declares the height and width as double

double height, width;

This line prompts user for height

cout<<"Enter wall height (feet): ";

This line gets user input for height

cin>>height;

This line prompts user for width

cout<<"Enter wall width (feet):  ";

This line gets user input for width

cin>>width;

//1  Question 1 begins here

This line declares area as double

double area;

The line calculates area

area = width * height;

The line prints the calculated area

cout<<"Wall area: "<<area<<" square feet"<<"\n";

//2  Question 2 begins here

This line declares and calculates gallon as a constant double variable

const double gallon = area/350.0;

This line prints the calculated gallon

cout<<"Paint needed: "<<gallon<<" gallons"<<"\n";

//3  Question 3 begins here

This line rounds gallon to nearest whole number and prints the result

cout << "Cans needed :" << round(gallon) << " can(s)";  

Ver imagen MrRoyal