Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

suppose the input is 3. what is the value of beta afterthe following c++ code ex

ID: 3616854 • Letter: S

Question

suppose the input is 3. what is the value of beta afterthe following c++ code executes: cin >> beta; switch (beta) { case 3:    beta = beta + 3; case 1:    beta ++;    break; case 5:    beta = beta + 5; case 4:    beta = beta + 4; } I have no idea how this works. keep reading the book butit makes no sense. if i could get an explanation of what the"breaks" mean and what it means by "switch", it would begreat. then if i could get a run thru of what this code doeswith the input after each line it would be great suppose the input is 3. what is the value of beta afterthe following c++ code executes: cin >> beta; switch (beta) { case 3:    beta = beta + 3; case 1:    beta ++;    break; case 5:    beta = beta + 5; case 4:    beta = beta + 4; } I have no idea how this works. keep reading the book butit makes no sense. if i could get an explanation of what the"breaks" mean and what it means by "switch", it would begreat. then if i could get a run thru of what this code doeswith the input after each line it would be great

Explanation / Answer

#include<iostream.h>
#include<conio.h>
int main()
{
int beta;
cout<<"Enter a Number in beta: ";
cin >> beta;
switch (beta)  //suppose you provide 3 in beta
{
case 3:   //condition true
   beta = beta + 3; //now beta is 6  
case 1:   //now beta is 7
   beta ++;
   break;  //exits from the switchstatement
case 5:
   beta = beta + 5;
case 4:
   beta = beta + 4;
}

cout<<"Beta Valueafter switch: "<<beta;
getch();
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int beta;
cout<<"Enter a Number in beta: ";
cin >> beta;      //supposeuser enter 3
switch (beta)  //suppose you provide 3 in beta
{
case3:                           //conditiontrue
   beta = beta +3;          //nowbeta value is 6  
case1:                           //nowbeta will enter in this case and become 7
   beta ++;
  break;                             //exitsfrom the switch statement, beta will not change in remainingcases
case 5:
   beta = beta + 5;
case 4:
   beta = beta + 4;
}