I posted in this forum a few days ago about a program I was having trouble with.
"A user enters 3 numbers, the program will sort the 3 numbers in ascending order and descending order, displaying both orders to the user. Only use if and else statements, no arrays,or anything else.
So i figured out how to code this, but it only works in certain instances.
if i enter single digit numbers in the order of 1,3,2 the program sorts it in the correct order with no problems. However if I start entering larger numbers in the order of 1000,700,950 for example. My program completely skips the second number. Why is this?
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double numOne = 0.0;
double numTwo = 0.0;
double numThree = 0.0;
double First = 0.0;
double Second = 0.0;
double Third = 0.0;
cout << "Enter your first number: " << endl;
cin >> numOne;
cout << "Enter you second number: " << endl;
cin >> numTwo;
cout << "Enter you third number: " << endl;
cin >> numThree;
if ((numOne < numTwo) && (numOne < numThree))
First = numOne;
elseif ((numTwo < numOne) && (numTwo < numThree))
First = numTwo;
else
First = numThree;
if ((numOne < numThree) && (numOne > numTwo))
Second = numOne;
elseif ((numTwo < numThree) && (numTwo > numOne))
Second = numTwo;
else
Second = numThree;
if ((numOne > numTwo) && (numOne > numThree))
Third = numThree;
elseif ((numTwo > numOne) && (numTwo > numThree))
Third = numTwo;
else
Third = numThree;
cout << "This is the ascending order" << endl;
cout << "The first number is: " << First << endl;
cout << "The second number is: " << Second << endl;
cout << "The third number is: " << Third << endl;
cout << " " << endl;
cout << "This is the descending order" << endl;
cout << "The third number is: " << Third << endl;
cout << "The second number is: " << Second << endl;
cout << "The First number is: " << First << endl;
system("pause");
return 0;
}//end of main function