How would i make this work?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 534 Views - Last Post: 31 January 2018 - 05:41 PM Rate Topic: -----

#1 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}
:code:

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  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}



Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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
Was This Post Helpful? 1
  • +
  • -

#5 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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/
Was This Post Helpful? 0
  • +
  • -

#7 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • Joined: 12-June 08

Re: How would i make this work?

Posted 13 January 2018 - 03:51 PM

Again.. What ARE you getting?
Was This Post Helpful? 0
  • +
  • -

#9 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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.
Was This Post Helpful? 0
  • +
  • -

#11 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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).

Was This Post Helpful? 0
  • +
  • -

#13 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13758
  • View blog
  • Posts: 54,934
  • 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?

Have you fixed your order of operations for your final formula?
Was This Post Helpful? 0
  • +
  • -

#15 jaredjamesthewizard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2