So I recently started with C++ and one challenge is to create a program that asks for two numbers and it has to say either if; one of the numbers is positive, both are positive or neither are positive. I tried to make a switch structure without if's but It does not seem to work out. Here's my code.
#include <iostream>
using namespace std;
int main()
{
int number;
int number2;
cout <<"Introduce two numbers:" ;
cin >> number, number2;
switch(number)
{
case (number > 0) (number2 > 0): cout <<"Both numbers are positive.";
break;
case (number > 0) (number2 < 0): cout <<"One of the numbers is positive.";
break;
case (number < 0) (number2 > 0): cout <<"One of the numbers is positive.";
break;
case (number < 0) (number2 < 0): cout <<"None of the numbers are positive.";
break;
default: cout <<"It must be a number.";
}
return 0;
}
The compilation errors I get are the following. In function 'int main()':
[Error] 'number' cannot appear in a constant-expression
[Error] 'number2' cannot appear in a constant-expression
[Error] a function call cannot appear in a constant-expression
[Error] 'number' cannot appear in a constant-expression
[Error] 'number2' cannot appear in a constant-expression
[Error] a function call cannot appear in a constant-expression
[Error] 'number' cannot appear in a constant-expression
[Error] 'number2' cannot appear in a constant-expression
[Error] a function call cannot appear in a constant-expression
[Error] 'number' cannot appear in a constant-expression
[Error] 'number2' cannot appear in a constant-expression
[Error] a function call cannot appear in a constant-expression