Q:

write c++ program to read the input and check whether the number is positive, negative, or zero using the switch statement only

0

write c++ program to read the input and check whether the number is positive, negative, or zero using the switch statement only

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
       int num;

    cout<<"Enter any number: ";
    cin>>num;

    switch (num>0)
    {
        // Num is positive
        case 1:
            cout<<num<<" is positive.";
        break;
        // Num is either negative or zero
        case 0:
            switch (num < 0)
            {
                case 1: 
                    cout<<num<<" is negative.";
                    break;
                case 0:
                    cout<<num<<" is zero.";
                    break;
            }
        break;
    }

    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now