A Simple Problem

I am extremely new to programming... like working on my first program.
I cannot seem to get this right:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <iostream>
#include <iomanip>
#include <cmath>
	using namespace std;

int main()
{
	float fHeight, fWidth, fLength, fPaintSpace, fGallonCost, fArea, fArea2, fCost;

	cout << "Welcome to the Paint Calculator (version 1.0.0)!\n\n";
	cout << "What is the height of the room to be painted?\n";
	cin >> fHeight;
	cout << "What is the width of the room to be painted?\n";
	cin >> fWidth;
	cout << "What is the length of the room to be painted?\n";
	cin >> fLength;
	cout << "How much space can one gallon of the desired paint cover?\n";
	cin >> fPaintSpace;
	cout << "How much does one gallon of the desired paint cost?\n";
	cin >> fGallonCost;

	fArea = fHeight * fWidth;
	fArea2 = fHeight * fLength;
	fArea *= 2;
	fArea2 *= 2;
	fArea += fArea2;
	fArea = fArea / fPaintSpace;
	fCost = (ceil (fArea)) * fGallonCost;

	cout << "\nYou will need " << ceil (fArea) << " gallons of paint.\n";
	cout << "Which will cost $" << setprecision(2) << fixed << fCost << endl;

	return 0;
} // end main 


I ran it with a test value of fGallonCost 10, the program then proceeded to tell me that I needed one gallon with a cost of 20. I know that this must be a logic error... come one though, I am a new programmer and I'm only in my early 20's. That's to be expected right?
You should provide us with the input numbers you used for each variable. Just makes it easier for us to duplicate your problem.

Edit: Basic check shows it works correctly to me.
Last edited on
8.8 - height
8.8 - width
8.8 - length
300 - paint space
10.00 - gallon cost
I tried it with a Heigth of 1, Width 1, Length 1, Paint space 1, and cost 1. And I get only $4. So excluding the floor, I think you're missing a another side somewhere, maybe ceiling? O.o

Maybe changing fArea2 *= 2; to fArea2 *= 3; To include the ceiling.
Tried your numbers and got 2 gallons and $20, which looks OK.
Wow. I am sorry everyone. Like I said this is my first program ever. My error was in my syntax... sorry everyone.
Topic archived. No new replies allowed.