1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natta225 [31]
3 years ago
5

Give an example of an if/else statment and a case statment that are equivalent. Your example should contain at least three choic

es.
Computers and Technology
1 answer:
zimovet [89]3 years ago
4 0

Answer:

The if - else and equivalent switch case statements in c++ language are given below.

if ( ch == 1 )

       cout << " sum is " << x + y << endl;

   else if ( ch == 2 )

       cout << " difference is " << x - y << endl;

   else if ( ch == 3 )

   {

       cout << " Quitting " << endl;

       exit;

   }

switch( ch )

   {

       case 1 :    cout << " Sum is " << x + y << endl;

                   break;

       case 2 :    cout << " Difference is " << x - y << endl;

                   break;

       case 3 :    cout << " Quitting " << endl;

                   break;

   }      

Explanation:

The above statements use three variables which are declared and initialized as shown.

int x = 10;

    int y = 25;

    int ch;

The above statements execute for of addition, subtraction or to quit the program.

cout << " 1. Addition " << endl;

    cout << " 2. Subtraction. " << endl;

    cout << " 3. Quit " << endl;

    cout << " Enter your choice " << endl;

The variable ch holds the numerical option entered by the user.

    cin >> ch;

For if - else statements, the if statement is executed based on the value of variable ch entered by the user. After execution, the compiler goes out of the statements automatically.

Following the if – else, if any statement is present, it will be executed.

For switch case, every case ends with break keyword. After the required case is executed based on the value of variable ch entered by the user, the break statement is executed which causes the switch case to terminate the control goes out of the statements.

Following the switch case, if any statement is present, it will be executed.

You might be interested in
Amd relive how to download it says not fully installed help plz
Zinaida [17]
It is not fully installed because of storage or memory is not enough to install this app.

Hope this helps you :)



6 0
4 years ago
Which option of ms-word is used o represent data in an organised manner?
tekilochka [14]
Use the charting features of Word 2007 and Excel 2007 to present<span> your </span>data<span> in a pie, line, </span>
3 0
3 years ago
1.5 code practice question 3
Svetach [21]

Answer: What the hell is that 243 suppose to be

Explanation:uhg

4 0
3 years ago
I need this answer right away!
Degger [83]

Answer:

Foundation.

Bootstrap. 2.1 Resources.

Metro UI.

jQuery Mobile.

Sencha Touch.

Ionic.

HTML KickStart.

Semantic UI

Explanation:

5 0
3 years ago
What is SoC? how is it different from CPU?
slamgirl [31]

Answer:

SoC usually contains a GPU

Explanation:

Where as a CPU cannot function without dozens of other chips

6 0
3 years ago
Other questions:
  • What device operates at the network layer (layer 3) of the osi model and forwards packets across computer networks?
    7·1 answer
  • How do I upload a picture in python 3
    7·1 answer
  • 11.19 (Constructor Failure) Write a program that shows a constructor passing information about constructor failure to an excepti
    6·1 answer
  • What is the latest date you can file the FAFSA if you're planning to start
    6·2 answers
  • In Microsoft Word you can access the _______ command from the "Mini toolbar".
    7·1 answer
  • Can anyone help explain this?
    13·2 answers
  • Explain the role of computers in accounting
    11·1 answer
  • Give 3 reasons why it is believed that smart phones precent us from communicating face to face.give three reasons why it is beli
    8·1 answer
  • An international pharmaceutical company is fully compliant with local and international regulations. However, they suffered a ma
    14·1 answer
  • What does playstation network is currently undergoing maintenance?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!