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

Suppose that int variable. Consider the following C++ code: cin >> beta; switch

ID: 3650523 • Letter: S

Question

Suppose that int variable. Consider the following C++ code:

cin >> beta;
switch (beta % 7)
{
case 0:
case 1:
beta = beta * beta;
break;
case 2:
beta++;
break;
case 3:
beta = beta--;
break;
default:
beta = -10;
}

What is the output if the input is 11?
input is 12? Input is 0? Input is 16?

I have got it to compile but am missing something in my program to get a correct responce.
here is what i got
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
int beta = 11;

cin >> beta;
switch (beta % 7)
{
case 0:
case 1:
beta = beta * beta;
break;
case 2:
beta++;
break;
case 3:
beta = beta--;
break;
default:
beta = -10;
}

return 0;
}

Explanation / Answer

Try the following code: #include #include using namespace std; int main() { int temp = 11; int beta; beta = temp % 7; cin >> beta; // If you are handcoding beta why are you taking the input again? switch (beta) //dont calculate in switch use as written { case 0: //(You might want to add a break here) case 1: beta = beta * beta; break; case 2: beta++; break; case 3: beta = beta--; break; default: beta = -10; } return 0; } 11% 7 = 4 hence it ll have default value beta = -10 12% 7 = 5 hence it ll have default value beta = -10 Input 0 output 0 input 16 output beta = 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote