Thread: question about some variables in my code

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    72

    question about some variables in my code

    Hello guys!

    I want to program something that tells me how many gallons of paint I need and what the total cost of the painting . I gotta say I am new to this, I hope the question dosen't seem that silly

    Code:
    // Headers and Other Technical Items
    
    #include <iostream>  
    using namespace std;
    
    // Function Prototypes
    
    void pause(void);
    
    // 
    
    double       length;
    double       width;
    double       height;
    double       price_gal_paint;
    int          coverage_gal_paint;
    double       total_area;
    int          total_gal_paint;
    double       total_cost;
    //******************************************************
    // main
    //******************************************************
    
    int main(void)
      {
      // Input	
      cout << "\nEnter the price of 1 gallon of paint";
      cin >> price_gal_paint;
      cout << "\nEnter the length of the house ";
      cin >> length;
      cout << "\nEnter the width of the house ";
      cin >> width;
      cout << "\nEnter the height of the house ";
      cin >> height;
      cout << "\nEnter the amount of square foot one gallon will cover ";
      cin >> coverage_gal_paint;
      // Process
      
      // calculate the total area of the building by
      x = length * height * 2 ;
      y = width * height * 2;
      total_area = x + y;
      
      //calculate the number of gallons of paint needed by
      
      total_gal_paint = total_area / coverage_gal_paint;
      total_gal_paint = total_area / coverage_gal_paint + 0.9999;
      
      total_cost = total_gal_paint * price_gal_pain;
      // Output
      cout << "\nThe number of gallons of paint is -------->: ";
      cout << answer;
      cout << "\nThe total cost of the paint is -------->: ";
      cout << answer;
      pause();
      return 0;
      }
    
    //******************************************************
    // pause
    //******************************************************
    
    void pause(void)
      {
      cout << "\n\n";
      system("PAUSE");
      cout << "\n\n";
      return;
      }
    I hope everything is right. But I do have a question about the following code..

    Code:
     // calculate the total area of the building by
      x = length * height * 2 ;
      y = width * height * 2;
      total_area = x + y;
    I know it cant be just x and y now. But if I did total_area for x and y it wouldn't calculate it right. I think I have enough variables.. I don't know.. I kinda don't know how do do this part.
    I believe I need to more variables for this..?

    Thank you!!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since the formula for area of a really-open box (no floor or ceiling) is 2lh+2wh, you could just assign that to total_area, without doing it in stages like you're currently doing.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    72
    Well, but I would like to do it this way. Makes it kinda esier for me. Can I still assign total_area to it?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you mean assign "it" to total_area, then I suppose, depending on what "it" is.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    72
    Sorry, I mean it like this:

    PHP Code:

    // calculate the total area of the building by
      
    total_area length height ;
      
    total_area width height 2;
      
    total_area y
    As I already said, this looks wrong to me. Maybe it is not..not sure. But then You have 3 values assigned to total_area instead of just the result.

    Edit:

    No, that dosen't work. I forgot about the total_area = x + y. Of course, it couldn't be x and y. Seems so easy..but I just do't get it.

    I got it working now. But I still would like to know how do to it the way I wanted to do it. I took 2lh+2wh
    Last edited by XodoX; 02-03-2009 at 08:03 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Tutorial sample code question
    By Kalleos in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 12:20 PM
  2. Data Storage Question, and Dynamic variables?
    By Zeusbwr in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2004, 11:01 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. question regarding code found on this board
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-23-2002, 08:03 PM