Concept explainers
Complete the following
#include <iostream>
using namespace std;
int main()
{
int userNum;
cout << "Enter one of the numbers 1, 2, or 3: ”;
cin >> userNum;
//
// Write the switch statement here.
//
return 0;
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (9th Edition)
Starting Out with C++: Early Objects
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Concepts of Programming Languages (11th Edition)
- Write a program that prompts the user to enter a number within the range of 1 through 10. Theprogram should display the Roman numeral version of that number. If the number is outside therange of 1 through 10, the program should display an error message. The following table showsthe Roman numerals for the numbers 1 through 10: Using if else if or if elif else statementarrow_forwardc++ programming if…else and switch case are types of conditional selection statements used in many programming languages such as C++. Write your own codes for question (a), (b) and (c) to demonstrate how the selection statement works. (a) Using if….else selection statement, allow user to key in a number then check whether the number is positive or negative number. (b) Using if….else...if selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 .. (c) Using nested if..else selection statement, ask user to key in their age. Then define whether the user should go to nursery, primary school, secondary school or university based on their input. (d) Using switch case selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 .arrow_forward3. Write an if statement that assigns 0.4 to commission if sales is greater than or equal to 10000. In C++ language.arrow_forward
- this is c program Write program that ask the user to enter int mark (0-100) for test Physics. Thencategorise the student based on the following grading system. Use else-if and switchstatements.Value output80-100 Gred A; Excellent60-79 Gred B; Very Good.40-59 Gred C;Good.0-39 Gred F;Failarrow_forwardQ-Write a program using if statement instead of switch statement. x=2; switch x case 1; disp(‘One’) case 2; disp(‘Two’) case 3; disp(‘Three’) otherwise; disp(‘Unknown Number’) endarrow_forwardIn C++, write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order using a combination of if-else statements.arrow_forward
- Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If 'b' or 'B', print "Beta". For any other character, print "Unknown". Use fall-through as appropriate. End with newline. #include <iostream>using namespace std; int main() { char origLetter; cin >> origLetter; /* Your solution goes here */ return 0;}arrow_forwardWrite a program that prints the insurance fee to pay for a pet according to the following rules: (Note: must use a switch statement to determine pet fee) A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been neutered costs $40.A cat that has not been neutered costs $60.A bird or reptile costs nothing.Any other animal generates an error message. The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered status(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case. It prints out the type of animal (full name of animal)…arrow_forwardIN C LANGUAGE Write a menu-driven program for the following, use case/switch statement:LOL MENU1. QUADRATIC EQUATION 2. BMI CALCULATOR 3. SUM OF ODD NUMBERS 4. EXIT CHOICE:NOTE: Input another choice, if the choice is invalid. Case 1: password to open: 1111 (back to main if the password is invalid) Create a program that will calculate and display the real roots of the quadratic equation: ax2 + bx + c = 0 using the quadratic formula: x = (-b ± sqrt of b2 - 4ac) / 2a Make sure that the b2 > 4ac, so that the calculated roots will always be real. And that a must not be equivalent or less than 0. Note: Back to main after performing case 1 or exit Case 2: password to open: 1234 (back to main if the password is invalid) Create a program that will calculate Body Mass Index (BMI) and will indicate the status of your BMI. Using ladderized if-else. BMI = ([Weight in Pounds) / (Height in inches) x (Height in inches)] x 703 BMI = (Weight in Kilograms) / (Height in meters) x (Height in…arrow_forward
- In c program Write an interactive program that contains an if statement that may be used to compute the area of a square ( area=side2) or a circle ( area=p*radius2) after prompting the user to type the first character of the figure name ( S or C).arrow_forwardA pair of primes that vary by two is a pair of twin primes (e.g., 3 and 5, 101 and 103). Write a C++ application that displays the total number of twin primes smaller than 1000.arrow_forwardCoding language c Write C program that will prompt the user for an integer n. If the user hasentered a non-integer, the user must be prompted again until he or she enters aninteger. If he enters non-integer numbers five times, the program must inform theuser the following message‘You have entered non-integers on five occasions, now the program is exiting”before coming to an end.On the other hand, if the user enters an integer n, the program must compute thesum of three consecutive factorials S=n!+(n+1)!+(n+2)! . Your program mustprint the resulting sum on the displayarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr