Concept explainers
(Replacing switch with if ... else)Rewrite the program of Fig. 4.7 by replacing the switch statement with a nested if ... else statement; be careful to deal with the default case properly Then rewrite this new version by replacing the nested if ... else statement with a series of if statements; here, too, be careful to deal with the default case properly (this is more difficult than in the nested if … else version). This exercise demonstrates that switch is a convenience and that any switch statement can be written with only single-selection statements.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Digital Fundamentals (11th Edition)
Experiencing MIS
Starting Out with Python (3rd Edition)
Starting out with Visual C# (4th Edition)
C Programming Language
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Question #1 Study the following C program and answer the below questions Hint: you might run it in Dev C++ before starting answering the questions! #include int main(void) { int number; char choice; printf("Please enter an integer number: " ) ; scanf("%d" , &number); printf("\nTo check whether the number is even or odd, press e \n"); printf("To check whether the number is positive or negative, press p \n"); printf("To check whether the number is multiple of 10, press m \n"); printf("\nPlease enter your choice: "); scanf(" %c" , &choice); switch(choice) { case 'e': case 'E': if (number % 2 == 0){ printf("\n%d is even \n" , number); } else { printf("\n%d is odd \n" , number); break; case 'p': case 'P': if (number > 0){ printf"\n%d is positive \n" , number); else if (number < 0){ printf("\n%d is negative \n" , number); } else { printf"\n%d is zero! \n" , number); break; case 'm': case 'M': if (number % 10 == 0){ printf("\n%d is a multiple of 10 \n" , number); } else { printf"\n%d is NOT a…arrow_forwardWhat is the difference between the statements continue and break?arrow_forwardAnalyze the following statements carefully and decide whether the statements that appear after the code are true or false.arrow_forward
- Singular to Plural. Create a program that accepts a word in singular, and produces the corresponding plural. Use the following rules: a. If the word end in ‑s, -ss, -sh, -ch, -x, or –z, then add –es to the word. For example, the plural of tax is taxes b. If the word ends in -fe, then replace the ending with –ves. For example, the plural of wolf is wolves c. If the word ends in y and the previous letter is a vowel, then add –s to the word. For example, the plural of boy is boys d. If the word ends in y and the previous letter is a consonant, then change the –y ending with –ies. For example, the plural of city is cities e. If the word does not meet the criteria above, then add –s to it.arrow_forwardcircles) Write a program that prompts the user to enter the center coordinates and radii of two circles and determines whether the second circle is inside the first or overlaps with the first, as shown in Figure 4.11. (Hint: circle2 is inside circle1 if the distance between the two centers <= | r1 - r2| and circle2 overlaps circle1 if the distance between the two centers <= r1 + r2.arrow_forward10) Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. The symbol + increases the numeric value by 0.3, and the symbol - decreases it by 0.3. For example: Enter a letter grade: B- The numeric value of B- is 2.7.arrow_forward
- Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements: (a) Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual.arrow_forwardWhich of the following statements is true about the difference between while looping and do..while looping? a) while loops require brackets to be syntactically correct b) only do while loops require a condition c) while loops must mutate a variable in order to break d) do while loops ensure that the body executes at least oncearrow_forward1. Write program to check whether a number is Palindrome or not. [Hint]: A palindrome number is a number such that if we reverse it, it will not change. For example some palindrome numbers examples are 121, 212, 12321 , 454.arrow_forward
- 12: guess.cpp) Write a program that plays a guessing game with the user. The user should pick a letter, and the computer should try to guess the letter. After each guess, the user should tell the computer whether its guess was too high or too low. With this information, the computer should be able to guess the letter within five tries. The user should be able to give whole words or single upper or lower case letters as responses.arrow_forwardIndicate whether the argument is valid or invalid. For valid arguments, prove that the argument is valid using a truth table. For invalid arguments, give truth values for the variables showing that the argument is not valid.arrow_forwardState whether the following are true or false. If the answer is false, explain why.b) The break statement is required in the default case of a switch selection statement.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