c. Write a complete program that can displays output as shown in the samples in Figure 2.1 The program will prompt the user for two (2) integer numbers. Then, the program will display a calculator menu and prompt the user to enter his choice. If the user enters 1 / 2 / 3, the program will perform the calculation according to the choice, display the result of the calculation and end the program. If the user enters 4, the program will display "Exit" and ends. An error message "Invalid input" will be displayed if the user enters a number outside the range of 1 - 4. lease enter at teri a Piease enter and unber i 1 Please enter lat uberi e Piease enter and nunber lease enter lst nube lease enter and nuber Zease enter et ease enter and n kaleulator kateutator caleulater . Ad te nubers 2. Sutract te nubers b. Mitiply tvo ubers . Quit Add te nunbers Subtract te nbers Mltiply te nubers . it Add te nuters 2. Suetract te nuters P. itiply to ubers . Quit Add te nuters 2. Sutrect te ters b. itiply twe nubers . Quit nter your chelce(1- 4): Enter your choice(1 4)I1 Enter your cheice(4) Enter your choice(1- 4) 14 2. 21- 252 Invalid input Samples of output
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Step by step
Solved in 2 steps with 1 images