Question

Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << Ente
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Here is your code you have to use the conditions in switch case where we are using ternary operartor if number greater than 0 execute case 0
  • else check if number is less than 0 execute case 1
  • else execute case 2

#include<bits/stdc++.h>
using namespace std;
int main(){
   int number;
   cout<<"Enter the number:";
   cin>>number;
   switch(number > 0 ? 0 : (number < 0 ? 1:2)){
       case 0:{
           cout<<"You entered a Positive Integer:"<<number<<endl;
           break;
       }
   case 1:{
       cout<<"You entered a negative Integer:"<<number<<endl;
           break;
       }
  
case 2:{
           cout<<"You entered 0"<<endl;
           break;
       }
}
cout<<"This line is always printed";

return 0;}

Thanks Hope it will help you!

Add a comment
Know the answer?
Add Answer to:
Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT