Submitted by: Submitted by ctbailbondgal
Views: 411
Words: 403
Pages: 2
Category: Science and Technology
Date Submitted: 02/01/2014 07:35 PM
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 case of division by zero.
A. Problem Analysis –
Our program is to calculate two inputted numbers; the output of the program will be the answer.
The values of the two numbers and the user’s option are given as the inputs for this program.
The next step will be to determine which operation needs to be executed. This will be done using multiple selection structures with one of the following formulas.
a + b
a - b
a * b
a / b
In summary, here are the input, output, and calculation data.
1. INPUT DATA:
a. First number (a)
b. Second number (b)
c. Choose addition (1), subtraction (2), multiplication (3), division (4)
2. OUTPUT DATA: Answer based on user input.
3. CALCULATION DATA: The output can be obtained from the input data by using multiple selection structures (IF-THEN)
B. Program Design –
This module will consist of the following modules:
Main Module
Input Module
Calculation Module
Output Module
End Program
Main module
//Prompt to show the function of the program
Write “"Welcome, this program will calculate the result of a selected operation on two numbers."
//Declare all input and output variables
Declare a As Integer
Declare b As Integer
Declare A As Integer
Declare S As Integer
Declare M As Integer
Declare D As Integer
//Call other modules to perform the tasks
Call Input Module
Call Calculation Module
Call output Module
End Program
Input Module
// Input the first number, second number, and the selection for calculation method
Write “"Enter your first number."
Input a
Write "Enter your second number."
Input b
Write "Enter '1' for addition, '2' for subtraction, '3' for multiplication or '4' for division."
Input 1, 2, 3, or 4
Calculation Module
//Use If-Then method with selection structures in...