Homework Help Question & Answers

Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...


Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; sw
Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }
0 0
Add a comment
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 Coin

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
Free Homework 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.