Concept explainers
Rewrite the following
int selection;
cout << "Which formula do you want to see?\n\n";
cout << "1. Area of a circle\n";
cout << "2. Area of a rectangle\n";
cout << "3. Area of a cylinder\n"
cout << "4. None of them!\n";
cin >> selection;
1f (selection == 1)
cout << "Pi times radius squared\n";
else if (selection == 2)
cout << "Length times width\n";
else if (selection == 3)
cout << "Pi times radius squared times height\n";
else if (selection == 4)
cout << "Well okay then, good-bye!\n";
else
cout << "Not good with numbers, eh?\n";
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with C++: Early Objects
Additional Engineering Textbook Solutions
Computer Science: An Overview (12th Edition)
Absolute Java (6th Edition)
Database Concepts (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Rewrite the following expressions using an if . . . else statement. (Assume that all variables are declared properly.) (9) a. (overSpeed > 10) ? fine = 200 : fine = 75; b. (fuel >= 10) ? drive = 150 : drive = 30; c. (bill >= 50.00) ? tip = 0.20 : tip = 0.10;arrow_forwardUsing Switch statement, write a program that displays the following menu for the food items available to take order from the customer: Rice = $ 12.50 Sugar= $ 4.25 Tea= $3.75 Milk= $ 1.00 The program inputs the type of food and quantity. It finally displays the total charges for the order according to following criteria: Your output should be as follows:arrow_forwardRewrite the following switch statement using a nested if-else structure (assume that n is a previously declared int variable): switch (n) { case 1: cout << "ONE"; break; case 2: cout << "TWO"; case 3: cout << "THREE"; break; default: cout << "PASS"; }arrow_forward
- Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". End with a newline. Remember to use println instead of print to output a newline.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_forwardA. Rewrite the following program using switch statement:int main(){int testScore; // Holds a numeric test scorechar grade; // Holds a letter gradecout << "Enter your test score and I will tell you\n";cout << "the letter grade you earned: ";cin >> testScore;if (testScore = = 60)grade = 'F';if (testScore = = 70)grade = 'D';if (testScore = = 80)grade = 'C';if (testScore = = 90)grade = 'B';if (testScore = = 100)grade = 'A';cout << "Your grade is " << grade << ".\n";return 0;} B. Rewrite the following code, replacing the do-while loop with a while loop. When you do this you will no longer need an if statement. int number;cout << "Enter an even number: ";do{ cin >> number;if (number % 2 != 0)cout << "Number must be even. Reenter number: ";} while (number % 2 != 0); C. Given an array definition as follows, write the codes which will determine the highest value.const int SIZE = 10;int numbers[SIZE] = {15, 6, 3, 11, 22, 4, 0, 1, 9, 12}; D.…arrow_forward
- v2 Question 6 What situation calls for a switch statement? Group of answer choices Use a switch statement when the switch statement is inside the main program. Use a switch statement when a for statement can not be used. Use a switch statement when a selection is in a repitition statement. Use a switch statement when a single control value determines which of several possible actions is to be taken. Use a switch statement when a selection is outside of repitition statement.arrow_forwardwrite a program to display fruit sales receipts. Apple: Pink Lady - $4.99/kilo, Fuji - $5.99/kilo. Orange: Hamlin - $2.99/kilo, Moro - $3.99/kilo. The program must use if-else statements and string format. The program must work exactly like the following examples. Each column occupies 15 spaces and is in the right alignment.arrow_forwardWrite a switch statement that prints out the word: “paid” if the value of a variable called bill is ‘P’, “unpaid” if the value of bill is ‘U’, “late” if bill = ‘L’, “zero” if bill = ‘Z’.arrow_forward
- IN PYTHONWrite a program that reads in a code (C for circumference and A for the area) and the radius of a circular pool, computes and displays the circumference or the area depending on the code entered. Use a switch statement for the selection. If the user enters any other character (other than C or A), the program should display that it is an invalid choice. (Formulas: Area = Πr2, Circumference = 2Πr, where Π = 3.14159, and r is the radius)arrow_forwardHow many case labels would a switch statement require to be equivalent to the following if statement? If (v==1) WriteLine(one); Else WriteLine(two); a. zero b. one c. two d. impossible to tellarrow_forwardQ- Write a program using an if statement instead of a switch statement. x = 2; Switch x case 1; Dis ("the one") case 2 de ("two") Case 3; dis ("three") otherwise; disp("unknown number") Endarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage