Problem: | How much will it cost to paint the dining room? |
If I know: | Price of a gallon of paint. How many square feet one gallon covers. What the area to be covered is. |
Divide the area to be painted by the number of square feet a gallon covers to get the number of gallons needed. Then multiply the number of gallons needed by the price. |
INPUT | ||||
\ | ||||
- > PROCESS | ||||
\ | ||||
- > OUTPUT |
Cost of a gallon of paint (price). Number of square feet a gallon of paint covers (ftpergal). Dimensions of the room (width, length, height). |
How much it costs to paint the dining room (cost). |
Calculate Area Calculate Gallons Needed Calculate Cost Print Cost |
Calculate Area
|
Area of Walls
|
PROGRAM PAINT(INPUT,OUTPUT);
CONST
WIDTH=15;
LENGTH=12;
HEIGHT=9;
PRICE=14;
SQFTPERGAL=350;
VAR
CAREA,WAREA,ROOMAREA,GALNEEDED,COST:INTEGER;
BEGIN
CAREA:=LENGTH*WIDTH;
WAREA:=2*(WIDTH*HEIGHT)+2*(LENGTH*HEIGHT);
ROOMAREA:=CAREA+WAREA;
GALNEEDED:=ROOMAREA DIV SQFTPERGAL + 1;
COST:=GALNEEDED*PRICE;
WRITE('COST TO PAINT DINING ROOM IS');
WRITELN(COST)
END.
and read them in as data |
PROGRAM PAINT2(INPUT,OUTPUT);
CONST
SQFTPERGAL=350;
VAR
CAREA,WAREA,ROOMAREA,GALNEEDED,COST,WIDTH,LENGTH,HEIGHT,PRICE:INTEGER;
BEGIN
READ(WIDTH,LENGTH,HEIGHT,PRICE);
CAREA:=LENGTH*WIDTH;
WAREA:=2*(WIDTH*HEIGHT)+2*(LENGTH*HEIGHT);
ROOMAREA:=CAREA+WAREA;
GALNEEDED:=ROOMAREA DIV SQFTPERGAL + 1;
COST:=GALNEEDED*PRICE;
WRITE('COST TO PAINT DINING ROOM IS');
WRITELN(COST)
END.
15 12 9 14
Top Down Design
|