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
DUE ASAP ! Program Assignment: 1. Implement the following 3 scheduling Algorithms: a. First Come, First...
DUE ASAP ! Program Assignment: 1. Implement the following 3 scheduling Algorithms: a. First Come, First Served (batch, non preemptive) (FCFS) b. Shortest Job First (batch, non preemptive) (SJF) c. Round Robin (preemptive) (RR) 2. Implement Using C or C++ on a Linux machine 3. To run the 3 scheduling algorithms, create a Priority Scheduling Program with menu options that will call the 3 scheduling programs, (fcfs, sjf, and Round Robin). These are simulation algorithms, that will be run from...
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...
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort...
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot = first index) algorithms. Compute the CPU processing time for all the algorithms for varying input sizes as follows: N = 102, 103, 104, 105, and 106 Use a random number generator to generate the inputs. Obtain the inputs from the following input ranges: 1- 103, 1 - 106, 1 – 109, 1 - 1012 Write down your results as a table (with...
*******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...
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...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
in C++ Write a program to use the IF ELSE statement in the following way. Have...
in C++ Write a program to use the IF ELSE statement in the following way. Have the user input a value, x If the value is less than 100, present, "you got 5% interest" and display on the screen the total of the X*1.05 Else print on the screen, "you got 10% interest", and display the value X*1.10.
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT