I wrote this code to sort 3 integers but I can't figure out how to add a 4th. The program is supposed to sort 4 integers using only if-else statements (no loops).
#include <iostream>
usingnamespace std;
int main ()
{
cout << "Enter 4 integers: ";
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a<b)
{
if (b<c)
{
cout << a << b << c << endl;
}
elseif (a<c)
{
cout << a << c << b << endl;
}
else cout << c << a << b << endl;
}
elseif (b<c)
{
if (c<a)
{
cout << b << c << a << endl;
}
elseif (b<a)
{
cout << b << a << c << endl;
}
else cout << a << b << c << endl;
}
elseif (c<a)
{
if (a<b)
{
cout << c << a << b << endl;
}
elseif (c<b)
{
cout << c << b << a << endl;
}
else cout << b << c << a << endl;
}
else
{
cout << a << b << c << d;
}
return 0;
}