# How would i make this work?

• (2 Pages)
• 1
• 2

## 20 Replies - 724 Views - Last Post: 31 January 2018 - 05:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=408705&amp;s=46b13cfff7945fd0f9d1776db60dbdd9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

# How would i make this work?

Posted 13 January 2018 - 03:15 PM

I'm starting out programming, and this one assignment is having me stumped. I can't seem to figure out how to get to the answer:

A room has one door, two windows, and a built-in bookshelf and it needs to be painted. Suppose that one gallon of paint can paint 120 square feet.

Write the program that prompts the user to input the lengths and widths of the door, each window, the bookshelf; and the length, width, and height of the room (in feet). The program outputs the amount of paint needed to paint the walls of the room (no ceiling and floor).

Enter the length and width of the door: 6 3

Enter the length and width of the first window: 3 3

Enter the length and width of second window: 3 4

Enter the length and width of the bookshelf: 5 5

Enter the length, width, and height of the room: 15 15 12

The amount of paint needed to paint the room: 5.46667 gallons.

```#include <iostream>
using namespace std;

int main ()
{
const int SquareFeetGallon = 120;

double doorLength;
double doorWidth;
double doorArea = (doorLength * doorWidth);

double FwindowLength;
double FwindowWidth;
double FwindowArea = (FwindowLength * FwindowWidth);

double SwindowLength;
double SwindowWidth;
double SwindowArea = (SwindowLength * SwindowWidth);

double windowArea = (FwindowArea + SwindowArea);

double bookshelfLength;
double bookshelfWidth;
double bookshelfArea = (bookshelfLength * bookshelfWidth);

double roomLength;
double roomWidth;
double roomHeight;
double roomArea = (roomLength * roomWidth * roomHeight);

double paint = (roomArea - (windowArea + bookshelfArea + doorArea) / SquareFeetGallon);

cout << "Enter the length of the door: ";
cin >> doorLength;
cout << "Enter the width of the door: ";
cin >> doorWidth;

cout << "Enter the length of the first window: ";
cin >> FwindowLength;
cout << "Enter the width of the first window: ";
cin >> FwindowWidth;

cout << "Enter the length of the second window: ";
cin >> SwindowLength;
cout << "Enter the width of the second window: ";
cin >> SwindowWidth;

cout << "Enter the length and width of the bookshelf: ";
cin >> bookshelfLength;
cout << "Enter the width of the bookshelf: ";
cin >> bookshelfWidth;

cout << "Enter the length of the room: ";
cin >> roomLength;
cout << "Enter the width of the room: ";
cin >> roomWidth;
cout << "Enter the height of the room: ";
cin >> roomHeight;

cout << "The amount of paint needed to paint the room: " << paint;

return 0;
}
```

This post has been edited by modi123_1: 13 January 2018 - 03:24 PM
Reason for edit:: In the future, please use the [code] tag button in the editor..

Is This A Good Question/Topic? 0

## Replies To: How would i make this work?

### #2 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 03:25 PM

You should do your calculations _AFTER_ you get the user input.

### #3 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 03:34 PM

I tried putting it after, but it still doesn't add up the desired output number:

``` #include <iostream>
using namespace std;

int main ()
{
const int SquareFeetGallon = 120;

double doorLength;
double doorWidth;
double doorArea;

double FwindowLength;
double FwindowWidth;
double FwindowArea;

double SwindowLength;
double SwindowWidth;
double SwindowArea;

double windowArea;

double bookshelfLength;
double bookshelfWidth;
double bookshelfArea;

double roomLength;
double roomWidth;
double roomHeight;
double roomArea;

double paint;

cout << "Enter the length of the door: ";
cin >> doorLength;
cout << "Enter the width of the door: ";
cin >> doorWidth;

doorArea = (doorLength * doorWidth);

cout << "Enter the length of the first window: ";
cin >> FwindowLength;
cout << "Enter the width of the first window: ";
cin >> FwindowWidth;

cout << "Enter the length of the second window: ";
cin >> SwindowLength;
cout << "Enter the width of the second window: ";
cin >> SwindowWidth;

windowArea = (FwindowArea + SwindowArea);

cout << "Enter the length and width of the bookshelf: ";
cin >> bookshelfLength;
cout << "Enter the width of the bookshelf: ";
cin >> bookshelfWidth;

cout << "Enter the length of the room: ";
cin >> roomLength;
cout << "Enter the width of the room: ";
cin >> roomWidth;
cout << "Enter the height of the room: ";
cin >> roomHeight;

roomArea = (roomLength * roomWidth * roomHeight);
paint = (roomArea - (windowArea + bookshelfArea + doorArea) / SquareFeetGallon);

cout << "The amount of paint needed to paint the room: " << paint;
}

```

### #4 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 03:39 PM

Looks like you are missing quite a few calculations.

FwindowArea
SwindowArea
bookshelfArea

### #5 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 03:45 PM

I tried it again but the calculations still didn't add up

``` #include <iostream>
using namespace std;

int main ()
{
const int SquareFeetGallon = 120;

double doorLength;
double doorWidth;
double doorArea;

double FwindowLength;
double FwindowWidth;
double FwindowArea;

double SwindowLength;
double SwindowWidth;
double SwindowArea;

double windowArea;

double bookshelfLength;
double bookshelfWidth;
double bookshelfArea;

double roomLength;
double roomWidth;
double roomHeight;
double roomArea;

double paint;

cout << "Enter the length of the door: ";
cin >> doorLength;
cout << "Enter the width of the door: ";
cin >> doorWidth;

doorArea = (doorLength * doorWidth);

cout << "Enter the length of the first window: ";
cin >> FwindowLength;
cout << "Enter the width of the first window: ";
cin >> FwindowWidth;

FwindowArea = (FwindowLength +FwindowWidth);

cout << "Enter the length of the second window: ";
cin >> SwindowLength;
cout << "Enter the width of the second window: ";
cin >> SwindowWidth;

SwindowArea = (SwindowLength + SwindowWidth);

windowArea = (FwindowArea + SwindowArea);

cout << "Enter the length and width of the bookshelf: ";
cin >> bookshelfLength;
cout << "Enter the width of the bookshelf: ";
cin >> bookshelfWidth;

bookshelfArea = (bookshelfLength + bookshelfWidth);

cout << "Enter the length of the room: ";
cin >> roomLength;
cout << "Enter the width of the room: ";
cin >> roomWidth;
cout << "Enter the height of the room: ";
cin >> roomHeight;

roomArea = (roomLength * roomWidth * roomHeight);
paint = (roomArea - (windowArea + bookshelfArea + doorArea) / SquareFeetGallon);

cout << "The amount of paint needed to paint the room: " << paint;
}

```

### #6 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 03:47 PM

What are you entering?
What is the output?
What should the output be/

### #7 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 03:50 PM

the output is this:

Enter the length and width of the door: 6 3

Enter the length and width of the first window: 3 3

Enter the length and width of second window: 3 4

Enter the length and width of the bookshelf: 5 5

Enter the length, width, and height of the room: 15 15 12

The amount of paint needed to paint the room: 5.46667 gallons.

I can't seem to get the 5.46667 though.

### #8 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 03:51 PM

Again.. What ARE you getting?

### #9 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 03:55 PM

I'm getting 2699.9 as the answer.

### #10 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 03:56 PM

Mkay.. so look at that last query. Does it make sense?

Remember - the compiler doesn't enforce PEMDAS as you would think.

### #11 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 04:11 PM

I'm using code blocks if that helps.

### #12 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 04:13 PM

That's not particularly responsive.

Also think about the room 'area' you are calculating. Is that actually area or is that volume?

Remember:

Quote

the walls of the room (no ceiling and floor).

### #13 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 04:19 PM

Ok i looked it over and i was calculating the volume and not the area of the room. After doing it, it gave me the number 224.658

### #14 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,201
• Joined: 12-June 08

## Re: How would i make this work?

Posted 13 January 2018 - 04:21 PM

How are you now doing the area?

### #15 jaredjamesthewizard

Reputation: 0
• Posts: 16
• Joined: 13-January 18

## Re: How would i make this work?

Posted 13 January 2018 - 04:30 PM

ok so i tried doing it this way:
```paint = (SquareFeetGallon/ roomArea - (windowArea + bookshelfArea + doorArea));
```

and i got a negative number