Documente Academic
Documente Profesional
Documente Cultură
Problem definition
Develop a menu-driven program that inputs two numbers and, at the user’s option, finds their
sum, difference, product, or quotient. Make sure that your program gives an error message in
1. Add
2. Subtract
3. Multiple
4. Divide
Conversion program
1. Sum of A and B
2. Subtract B from A
3. Multiple of A and B
4. Divide A by B
Please enter your selection:
II. Analysis
Before we start designing the program, we designate three things, which are what are the
Frist of all, we need to find out all the input data we have. It is a menu-driven program, so
user has to choose one of four menu options. That would be the first input data on problem
statement. Once user selects an option, the input data will be selected depending on what
menu user choose such as the two numbers for sum, the two numbers for subtract, the two
numbers for multiple and the two numbers for divide. All these values are not specified, thus
be the result value of user’s selection. For example, if the user chooses the case one menu,
which is add operation, the output will be the result of add operation, so as the other three
menus.
Finally, we need to identify how to use input data to get output data. The program is able
1. A + B
2. A - B
3. A * B
4. A / B
One thing that we have to make sure that the second value, which is B, on the case four
menu, cannot be zero because any number cannot divide by zero. We will need to show the
III. Design
We need to identify the input and output data to set up the pseudocode. The five input data
will be the user’s menu selection and the four operations. We named the five inputs as
menuselection for the user’s selection, the two number, A and B for add operation, the two
number, A and B for subtract operation, the two number, A and B for multiple operation, and
the two number, A and B for divide operation. Simply, we use A and B for the four menu, but
the output will be different depending on what menu user choose. Also, the output data will
be the result value of the input, which is menu selection. There will be the four output data
from the four input data like: resultsum, resultsubtract, resultmultiple, and resultdivide.
We divide three modules to run this program, which are display module to let user select the
menu, perform calculate module to process the operation from the selection of menu and with
two numbers that user typed, and output module to show the result of operation.
Since we have all named input and output data, we can start design the program. This is
Main module
//Declare input and output data
Declare menuselecition as integer
Declare A as integer
Declare B as integer
Declare resultsum as integer
Declare resultsubtract as integer
Declare resultmultiple as integer
Declare resultdivide as integer
//Display purpose of this program
Output “This program shows the result of sum A and B,”
Output “subtract B from A,”
Output “multiple of A and B,”
Output “divide A by B”
//call three modules
Call display menu module
Call perform calculate module
Call output module
End program
Display menu module
Output “Select the operation,”
Output “1. Sum of A and B,”
Output “2. Subtract B from A,”
Output “3. Multiple A and B,”
Output “4. Divide A by B”
Output “Please choose one of operations:” input menuselection
Output module
Case 1
Output “The first number is:” + A
Output “The second number is:” +B
Output “The result of sum A and B is:” +resultsum
Break
Case 2
Output “The first number is:” + A
Output “The second number is:” +B
Output “The result of subtract B from A is:” +resultsubtract
Break
Case 3
Output “The first number is:” + A
Output “The second number is:” +B
Output “The result of multiple A and B is:” +resultmultiple
Break
Case 4
Output “The first number is:” + A
Output “The second number is:” +B
Output “The result of divide A by B is:” +resultdivide
Break
End case
zero.
V. Flow chart
1. Main module
2. Display menu module
3. Perform calculate module
4. Output module
VI. Testing
This is the result by using test data. There were a couple errors when user enter wrong value,
which is that zero was typed on case 4, divide operation, and when user select the other number
by zero”. Also, the display show that the any number can’t divide by zero
Another error is that user chooses wrong number for the menu selection. We already set it up on
pseudocode that if the number is not selected, than it goes to invalid menu.