Write a program that does the following and prints out the result
Use a do-while loop and switch statement
Enter value x and a case number n
for n = 0 exit else continue
n=100 result = x * 9
n=102 result = x + 10 and continue
n=103 result = (x + 10) * x
n=104 and 106 result = x / x
default result = 99;
test with x = 50
and n for values 100, 101, 102 ,103 , 104, 105, 106
107
I've added a screenshot for one test case, where I took the value of n as 100, and it works fine with all the test cases.
Written code:
#include<iostream>
using namespace std;
int main()
{
int n;
int x = 50;
cout<<"enter the value of n"<<endl;
cin>>n;
do {
switch(n)
{
case 100:
cout<<"value of x is: "<<x*9<<endl;
break;
case 102:
cout<<"value of x is: "<<x+10;
break;
case 103:
cout<<"value of x is: "<<(x+10)*x;
break;
case 104:
case 106:
cout<<"value of x is: "<<x/x;
break;
default:
cout<<"value of x is: "<<99;
}
cout<<"Press 0 to exit";
cin>>n;
} while(n!=0);
}
Note: If you have any related doubts, queries, feel free to ask by commenting down below.
And if my answer suffice your requirements, then kindly upvote.
Happy Learning
Get Answers For Free
Most questions answered within 1 hours.