#include <iostream>
usingnamespace std;
int main()
{
int num1, num2;
cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;
switch (num1 < num2)
{
casetrue:
cout << num1 << " is the minimum number while " << num2 << " is the maximum number." << endl;
break;
casefalse:
cout << num1 << " is the maximum number while " << num2 << " is the minimum number." << endl;
break;
default:
cout << "The input is invalid." << endl;
}
cin.get();
// Tested and works
}
A switch statement is used to compare a set value to a list of constant values. This is why the conditionals you had would not work. The values of the numbers could change and evaluate differently. So, you need to evaluate the logical equation within the beginning of the switch and then compare the resulting value with constants true and false.
I'm assuming this is a school assignment. However, this is indeed a horrible way to do it. You are much better off doing this the way that mutexe said: with if statements.