Error in Program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

15th Oct 2022, 10:20 AM
Raja Irfan Ahmed
Raja Irfan Ahmed - avatar
2 Answers
+ 1
The logic prints 0 as negative. So you must first check n==0 , instead of n < 1 before;
15th Oct 2022, 12:40 PM
Jayakrishna 🇮🇳
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;
15th Oct 2022, 11:21 AM
SoloProg
SoloProg - avatar