View Single Post
Old Apr 5th, 2006, 2:44 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Two problems I can see:
1. The one that is causing your output problem is this code:
	cout << areaOfPizza <<
	cout << " square inches, then at " << price<< " cents per square\n";
You have an extra cout in there, which is putting out the value of cout in hex.
Change this to either
	cout << areaOfPizza <<
	" square inches, then at " << price<< " cents per square\n";
or
	cout << areaOfPizza;
	cout << " square inches, then at " << price<< " cents per square\n";
this happens several time in the code.

2. This calculation:
double getAreaOfPizza( double P_I, int size )
{
	return (P_I*(size/2)*(size/2));
}
will perform the size/2 as integer calculations first (because of the brackets), this will lead to a wrong result when you use an odd number.
Change this to
double getAreaOfPizza( double P_I, int size )
{
	return (P_I*size/2*size/2);
}
or
double getAreaOfPizza( double P_I, int size )
{
	return (P_I*(size/2.0)*(size/2.0));
}
As a side note, I wouldn't expect an area calulation to have PI passed in as a variable. It aint gonna change much, so you could probably have it as a global constant or a local constant inside the area function.
The Dark is offline   Reply With Quote