GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Feb-2009, 12:14
XodoX XodoX is offline
New Member
 
Join Date: Feb 2009
Posts: 4
XodoX is on a distinguished road

How many gallons of paint


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

CPP / C++ / C 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..

CPP / C++ / C 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  
Old 03-Feb-2009, 20:19
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: question about code


Quote:
Originally Posted by XodoX
Hello guys!

I hope everything is right. But I do have a question about the following code..

CPP / C++ / C 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!!
There are some errors with your code...(undeclared variables) and a conversion warning...

but to the "question about the following code"...

Calculating perimeter is: P = (2*L + 2*W).
Then the 'total_area' = P*height.

A sample run (after corrections) looks like this:
Code:
Enter the price of 1 gallon of paint 21.99 Enter the length of the house 50 Enter the width of the house 24 Enter the height of the house 10 Enter the amount of square foot one gallon will cover 400 The number of gallons of paint is -------->: 3 The total cost of the paint is -------->: 65.97
Is this closer to what you were seeking? I would also say to make the 'total_gal_paint' as type double too, as the #gals is actually a little more than 3.

Post another reply if you have more questions. Also check this article, where it mentions how to include the ceiling's area (if painting an interior room, of course), plus this tidbit:
Quote:
Originally Posted by BobVila
Coverage per gallon of paint varies depending on the texture and porosity of the surface. Experts suggest that one gallon of quality latex paint will cover approximately 400 square feet with one coat of paint. Surface texture also plays a role in coverage. When making calculations, it's important to plan for extra paint needed for rougher or more absorbent surfaces.

Just a few other side notes:
1. Why the global variables? All those should be inside main().
2. No need for a pause() function. cin.get() can accomplish the same thing.
3. Not sure what the purpose of the line with: + 0.9999 ??

HTH.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 06-Feb-2009, 15:01
XodoX XodoX is offline
New Member
 
Join Date: Feb 2009
Posts: 4
XodoX is on a distinguished road

Re: question about code


Hello!

Yes, thank you! So I need to declare one more variable? In your case P.
I also noticed the other errors when I ran it. Sorry.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble integrating console code into GUI Barman007 Java Forum 18 15-May-2008 13:05
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 03:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 14:48
Guidelines for posting requests for help - UPDATED! WaltP C Programming Language 0 21-Apr-2005 02:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:21.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.