compile

compile

Hi, I am trying to make a stupid little program here. can anyone tell me why this compiles fine but when ran, no matter what number I put down it tells me I am a size 6 and 7. Why does it not tell me one or the other?

// Determines if your foot size is 6 or 7

#include
int main()
{
float length;
cout << "Enter Your Foot Size:";
cin >> length;
cout <<"
";

if( (length > 7) && (length < 9.25) || (length == 9.25) ); // if length is greater than 7 and less than 9.25 or equal to 9.25
cout << "Size 6
"; // print "Size 6"
if( (length > 9.25) && (length < 9.625) ); // if length is greater than 9.25 and less than 9.265
cout << "Size 7
"; // print "Size 7"
return 0;
}

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Remove the semicolon at the end of these two lines.

if( (length > 7) && (length < 9.25) || (length == 9.25) );

and

if( (length > 9.25) && (length < 9.625) );

The code can be improved(?) by using

if( (length > 7) && (length < 9.25) || (length == 9.25) ) // if length is greater than 7 and less than 9.25 or equal to 9.25
cout << "Size 6
"; // print "Size 6"
else if( (length > 9.25) && (length < 9.625) ) // if length is greater than 9.25 and less than 9.265
cout << "Size 7
"; // print "Size 7"
else
cout << "Invalid input
";

Connectez-vous pour laisser un commentaire.