Question

Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; sw
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code:

Given code using, if-else selection:

#include <iostream> using namespace std; /*main function*/ int main() { /*variables*/ int num; /*read num value from the user

Output:

C:\Users\Kumar Reddi\Desktop\trail.exe 5 Default: Value is: 5 Process exited after 7.479 seconds with return value o Press an

Code in text format (See above image of code for indentation):

#include <iostream>
using namespace std;

/*main function*/
int main()
{
   /*variables*/
   int num;
   /*read num value from the user*/
   cin>>num;
   /*if value is 1*/
   if(num==1)
       cout<<"Case 1: Value is: "<<num<<endl;
   /*if value is 2*/
   else if(num==2)
   {
   }
   /*if value is 3*/
   else if(num==3)
       cout<<"Case3: Value is: "<<num<<endl;
   /*if value is any number except 1,2 and 3*/
   else
       cout<<"Default: Value is: "<<num<<endl;
   return 0;
}


Add a comment
Know the answer?
Add Answer to:
Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...
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