0
Error in Program
#include<iostream> using namespace std; int main() { int n; cout << "Enter number: "; cin >> n; (n >= 1) ? cout << "It is positive" :(n < 1) ? cout << "It is negative" :(n==0) ? cout << "It is equal to zero"; } Expected before token ';' Help me solve this problem.
2 Answers
+ 1
The logic prints 0 as negative. So you must first check n==0 , instead of n < 1 before;
0
n>0 ? cout << "It is positive"
: n<0 ? cout << "It is negative"
: cout << "It is equal to zero";
// Or
string r = n>0 ? "positive" : n<0 ? "negative" : "equal to zero";
cout << "It is " + r;