Question

Write a program that does the following and prints out the result          Use a do-while...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that...
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that are divisible by 5.
*******please don't copy and paste and don't use handwriting **** Q1: Using the below given ASCII...
*******please don't copy and paste and don't use handwriting **** Q1: Using the below given ASCII table (lowercase letters) convert the sentence “welcome to cci college” into binary values. a - 97 b - 98 c - 99 d - 100 e - 101 f - 102 g - 103 h - 104 i - 105 j - 106 k - 107 l - 108 m - 109 n - 110 o - 111 p - 112 q - 113...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Second question Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Q2: Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f)...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f) 101 North America 102 USA 101 103 Canada 101 104 USA-Northeast 102 105 USA-Southeast 102 106 USA-West 102 107 Mexico 101 Note: (p) = "primary key" and (f) = "foreign key". They are not part of the column names. Product product_id (p) product_name 1256 Gear - Large 4437 Gear - Small 5567 Crankshaft 7684 Sprocket Sales_Totals product_id (p)(f) region_id (p)(f) year (p) month (p)...
I'm trying to write a nested loop in Mips Assembly that prints out, for example, if...
I'm trying to write a nested loop in Mips Assembly that prints out, for example, if user input x was 5: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (spaces in between) So far my code is : li $v0, 5   #Ask for integer syscall move $t5, $v0 addi $t0, $zero, 0 For1:    slt $t1, $t0, $t5    beq $t1, $zero, Exit    add $s0, $s0, $t0    addi $t0, $t0, 1...
A) write a program the computes nx and store the result into y You can use...
A) write a program the computes nx and store the result into y You can use y = Math.pow( Mantissa, exponent) Requirements: Besides main() your program must have one method with two parameters, one double and one int n and x are positive numbers read from the keyboard if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry the user must be able to quit prior to entering...
The following table contains recorded values on a level transmitter of a tank that’s holding water....
The following table contains recorded values on a level transmitter of a tank that’s holding water. The samples are taken every hour for 24 hours. Hours 1 2 3 4 5 6 7 8 9 10 11 12 Litres 100 101 104 106 99 50 103 91 110 91 93 92 Hours 13 14 15 16 17 18 19 20 21 22 23 24 Litres 95 96 91 92 101 104 106 125 106 101 104 100 Calculate the following...
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 ..... my code: #include <iostream> using namespace std; int main() { int userNum; userNum = 40; /* Your solution goes here */ while (userNum != 1){ userNum = userNum/2; cout << userNum << " ";   } cout << endl; return 0; } ........ but as a result i...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT