How to do this problem?

double a=0.00;
switch (selection)
{
case 'p':
cout << "Pentagonal Pyramid Calculator\n";
cout << "Valid range [2.00 < edge length < 500.00]"<< endl;
cout << "EdgeLength:";
cin>> a;


if ((2.00<a) && (a>500.00))
{
cout << "Calculation for a Pentagonal Pyramid" << endl;

cout << "Edge length " << fixed << setprecision(2) << a <<endl;
}
else
{
cout << "Error - edge length out of range"<< endl;
}
cout << "\n";
break;





I have some question how to get range number between 2 and 5. The output must be get with decimal point number. but it is still show error whatever I put it there.
> if ((2.00<a) && (a>500.00))
Because your weird operand reversal makes nonsense of your expression.

if ( (a>2.00) && (a>500.00) )
basically means if a is greater than 500.

Try
if ( a >= 2.0 && a <= 500.0 )

Pentagonal Pyramid Calculator
Valid range [2.00 < edge length < 500.00]
EdgeLength: 2
Error - edge length out of range


That's what the problem want. however I change it ,nothing happen
Pentagonal Pyramid Calculator
Valid range [2.00 < edge length < 500.00]
EdgeLength: 2.0001 -------------------------------------
Calculations for a Pentagonal Pyramid Edge Length: 2.00


That is what the output obtain..
I got it. Thank you
Topic archived. No new replies allowed.