Concept explainers
Rewrite the following
#include <iostream> using namespace std; int main()
{
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; if (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”;
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 (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Computer Science: An Overview (12th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Problem Solving with C++ (9th Edition)
- Based on what you learned about if-else and switch statements, could you implement the following if-else code using a switch statement (assume numerical variable A exists in your workspace) and preserve its behavior? if A >= 3 disp('A is greater or equal to 3.') else disp('A is not greater or equal to 3') end Yes Noarrow_forwardRewrite 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_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_forward
- A. 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_forwardWhat is the difference between if and switch statement?arrow_forwardCorrect the following if statement below.#include <stdio.h>int main(void){int volt_1=12;if(volt_1 < 10);{printf("This prints inside the if function \n");}printf("This prints outside the if function \n");}arrow_forward
- What value will be displayed by the println statement and why?int [] first = {5, 7, 3, 2, 9, 11};int [] second = first;first[3] = 12;System.out.println(second[3]);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_forwardRewrite the following expressions using an if . . . else statement. (Assume that all variables are declared properly.)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_forward
- Re- write the following program by using switch statement int main() { int code; Cout<<"enter code(a or A, bo B"; Cin>>Code; If ( code == 'a' && code =='A'} cout < < ''Sometimes you win" cout<< " Sometimes you learn"; else if (code =='b' &&& code== 'B') cout < < ''Don't wait for the perfect moment"; cout<< " Take the moment and make it perfect"; else Cout<<"Wrong code entered"; 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_forwardWrite a switch statement that checks nextChoice. If 0, print "Rock". If 1, print "Paper". If 2, print "Scissors". For any other value, print "Unknown". End with newline. #include <iostream>using namespace std; int main() { int nextChoice; cin >> nextChoice; /* Your solution goes here */ return 0;}arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education