Alright, I'm working on a C++ program for my programming class, it's pretty basic(Since we're just starting) but I can't get it to work right.
#include "std_lib_facilities.h"
int main()
{
int num1, num2, num3;
int first = 0, second = 0, third = 0;
cout << "Enter 3 numbers(Seperate them with space.)\n";
while(cin >> num1 >> num2 >> num3){
if(num1 >= num2 && num1 >= num3)
first = num1;
else if(num2 >= num1 && num2 >= num3)
first = num2;
else
first = num3;
if(num1 <= first && num1 >= num2 && first != num2 || num1 <=first && num1 >= num3 && first != num3 )
second = num1;
else if(num2 <= first && num2 >= num1 && first != num1 || num2 <=first && num2 >= num3 && first != num3 )
second = num2;
else if(num3 <= first && num3 >= num2 && first != num2 || num3 <=first && num3 >= num1 && first != num1)
second = num3;
if(num1 <= num2 && num1 <= num3)
third = num1;
else if(num2 <= num1 && num2 <= num3)
third = num2;
else if(num3 <= num1 && num3 <= num2)
third = num3;
cout << first << ", " << second << ", " << third << '\n';
first = 0;
second = 0;
third = 0;
num1 = 0;
num2 = 0;
num3 = 0;
}
keep_window_open();
Problem description:
I know it's a bit bad and inefficient, but this is all we "know" in C++ so I don't want to overstep my boundaries(Plus I couldn't think of any other way to do it >_>). The program works in every instance except one. When the numbers are ordered like this 3 1 2 it'll out put 3, 3, 1 and I can't seem to find the problem, any suggestions?
edit
The program is supposed to order numbers from greatest to least. If there are any other instances of it not working please let me know.
Each if() statement only needs to make one comparison.