Hallo,
I have a homework question where I have to sort 3 ints. I have done it, but I think there is a better way to do it?
Anyone want to take a look?
Code:
int a,b,c;
// Check if 'a' is the smallest one
if( (a < b) && (a < c) )
{
cout << "A is smalles" << endl;
// If 'a' is the smallest, check which is the biggest
if(c < b)
cout << "B is biggest" << endl;
else
cout << "C is biggest" << endl;
}
// Check if 'b' is the smallest one
if( (b < a) && (b < c) )
{
cout << "B is smalles" << endl;
// If 'a' is the smallest, check which is the biggest
if(a < c)
cout << "C is biggest" << endl;
else
cout << "A is biggest" << endl;
}
// Check if 'c' is the smallest one
if( (c < a) && (c < b) )
{
cout << "C is smalles" << endl;
// If 'a' is the smallest, check which is the biggest
if(a < b)
cout << "B is biggest" << endl;
else
cout << "A is biggest" << endl;
}
I cant use any of the sort functions.