# Thread: three numbers in descending order

1. ## three numbers in descending order

Hi

The following code is incomplete.

1: I'm getting this error: undefined reference to `swapthree(float&, float&, float&)'| . I have been unable to understand the reason for this error and don't know what to fix. Please help me

2: Could you please tell me some general thumb rule to know how many if's, else if's I would need in such situation? Thanks.

Code:
```// swap3numbers.cpp
// swap three number so that they appear in descending order
// it is assumed entered numbers are distinct

#include <iostream>
#include <cstdlib>

using namespace std;

int swapthree(float& dummya, float& dummyb, float& dummyc);

int main()
{
float a, b, c;

cout << "enter a: "; cin >> a;
cout << "enter b: "; cin >> b;
cout << "enter c: "; cin >> c;

if ( swapthree(a, b, c) )

{
cout << "the entered numbers in descending order: " << a << " " << b
<< " " << c << endl;
}

else
{
cout << "some error\n";
}

system("pause");

return 0;
}

//-----------------------------------------------------------------
// swapthree() definition

int swapthree(float& dummya, float dummyb, float dummyc)
{

if (dummya > dummyb > dummyc)
{
return 1;
}

else if (dummya > dummyb && dummyb < dummyc)
{
float temp = dummyb;
dummyb = dummyc;
dummyc = temp;

return 1;
}

else if (dummyb > dummya > dummyc)
{
float temp = dummya;
dummya = dummyb;
dummyb = temp;

return 1;
}

}```

2. Look at your function prototype and function definition are they identical? The prototype, definition, and function call must all agree on the type and number of parameters.

Jim

3. Sorry, I don't know how I missed to see the obvious mistake! Thanks for pointing this out.

4. Hi

Do you think the following code rightly address the problem of arranging the three entered numbers in descending order? Please let me know. Thanks.

Code:
```// swap3numbers.cpp
// swap three number so that they appear in descending order
// it is assumed entered numbers are distinct

#include <iostream>
#include <cstdlib>

using namespace std;

int swapthree(float& dummya, float& dummyb, float& dummyc);

int main()
{
float a, b, c;

cout << "enter a: "; cin >> a;
cout << "enter b: "; cin >> b;
cout << "enter c: "; cin >> c;

if ( swapthree(a, b, c) )

{
cout << "the entered numbers in descending order: " << a << " " << b
<< " " << c << endl;
}

else if ( !swapthree(a, b, c) )
{
cout << "some error\n";
}

system("pause");

return 0;
}

//-----------------------------------------------------------------
// swapthree() definition

int swapthree(float& dummya, float& dummyb, float& dummyc)
{

if ( (dummya > dummyb) && (dummyb > dummyc) )
{
return 1;
}

else if ( (dummya > dummyc) && (dummyc > dummyb) )

{
float temp = dummyb;
dummyb = dummyc;
dummyc = temp;

return 1;
}

else if ( (dummyb > dummya) && (dummya > dummyc) )
{
float temp = dummya;
dummya = dummyb;
dummyb = temp;

return 1;
}

else if ( (dummyb > dummyc) && (dummyc > dummya) )
{
float temp = dummya;
dummya = dummyb;
dummyb = dummyc;
dummyc = temp;

return 1;
}

else if ( (dummyc > dummya) && (dummya > dummyb) )
{
float temp = dummya;
dummya = dummyc;
dummyc = dummyb;
dummyb = temp;

return 1;
}

else if ( (dummyc > dummyb) && (dummyb > dummya) )
{
float temp = dummyc;
dummyc = dummya;
dummya = temp;

return 1;
}

else
{
return 0;
}

}```