You are on page 1of 10

I.

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

the case of division by zero. Following is the list of menu:

1. Add

2. Subtract

3. Multiple

4. Divide

Conversion program

The two values, which are A and B, will be given by users.

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

inputs, output, and how do we get output by using input data.

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

we have to ask user to enter as well.


Secondly, we need to find out all the output data that we will have. The output data will

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

to get simple by using symbols like:

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

error message to user.

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

how we pseudocode for this program:

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

Perform calculate module


Select case of menuselection
Case 1 : Output “Please enter the first number A” Input A
Output “Please enter the second number B” Input B
Set resultsum = A + B
Break
Case 2 : Output “Please enter the first number A” Input A
Output “Please enter the second number B” Input B
Set resultsubtract = A - B
Break
Case 3 : Output “Please enter the first number A” Input A
Output “Please enter the second number B” Input B
Set resultmutiple = A * B
Break
Case 4 : Output “Please enter the first number A” Input A
Output “Please enter the second number B” Input B
Set resultdivie = A / B
Break
Default:
Output “Option” + menuselction +“is invalid.”
End case

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

IV. Test data

User’s selection A B Expected output


1 453 25 478
2 752 23 729
3 52 4 208
4 85 6 14.16667
4 157 0 Error!
For the last test data, we will not have output data because we cannot be able to divide by

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

then between 1 through 4 cases.


When user enter zero for the case 4 operation, the error message show up and say “Can’t divide

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.