179k views
2 votes
2. A room has one door and two windows, and it needs to be painted. Assume that 1 gallon of paint can paint 120 square feet; that the door is 8ft x 5ft and the windows are each 2ft x 3ft. (You will not paint the door or windows.) Write a program called Lab 1-2B to ask the user for the length, width & height of the room; then calculate 1) total square footage of walls to be painted and the 2) amount of paint needed. Then print both values with labels. C#

User Catsby
by
5.2k points

1 Answer

3 votes

Answer:

// code in C#.

using System;

class WallPaint {

static void Main()

{

//variables

double l,w,h;

double win_area,door_area;

double amount_gallon;

Console.WriteLine("enter length of room:");

// read the length of room

l= Convert.ToDouble(Console.ReadLine());

Console.WriteLine("enter width of room:");

// read the width of room

w= Convert.ToDouble(Console.ReadLine());

Console.WriteLine("enter height of room:");

// read the height of room

h= Convert.ToDouble(Console.ReadLine());

Console.WriteLine("enter amount of a gallon:");

// read the amount of a gallon

amount_gallon= Convert.ToDouble(Console.ReadLine());

// find the area of both window

win_area=2*(2*3);

// area of door

door_area=8*5;

// total area of all walls

double tot_room_area=2*(l*h)+2*(w*h);

// area to be painted

double paint_area=tot_room_area-(win_area+door_area);

// gallos of paint required

double no_gallon=paint_area/120;

// total amount of paint

double tot_amount=no_gallon*amount_gallon;

// print the area to be painted

Console.WriteLine("total square footage of walls to be painted : "+paint_area);

// print amount of paint

Console.WriteLine("total amount of paint is: "+tot_amount);

}

}

Step-by-step explanation:

Read the length, width and height of the room from user.Read the amount of paint per gallon from user.Calculate the total area of all the walls.Calculate the area or window and door.Then find the area to be painted by subtracting window and door area from total wall area.Then find the number of gallon of paint required to paint all the area.Then calculate the total amount of the paint.

Output:

enter length of room:

10

enter width of room:

8

enter height of room:

12

enter amount of a gallon:

15

total square footage of walls to be painted : 380

total amount of paint is: 47.5

User Alex Essilfie
by
5.3k points