Write a program using pseudocode to create four functions add(a,b) to add a and b then return the result, similarly sub(a,b), mult(a,b), div(a,b) to perform mathematical operations. Provide a menu to choose which calculation to perform. Parameters a and b are inputs from user.
Start add(a,b):
return a+b
Stop
Start sub(a,b):
return a-b
Stop
Start mult(a,b):
return a*b
Stop
Start div(a,b):
return a/b
Stop
Start main:
Declare integer ch=-1
Declare float number1
Declare float number2
Declare float sum
Declare float difference
Declare float product
Declare float d
while ch<>5:
Display "MENU OF OPERATIONS"
Display "[ 1 ] - Addition"
Display "[ 2 ] - Subtraction"
Display "[ 3 ] - Multiplication"
Display "[ 4 ] - Division"
Display "[ 5 ] - Quit"
Display "Enter Your Choice: "
Read ch
if ch=1 then
Display "You have chosen Addition!"
Display "Enter the number 1: "
Read number1
Display "Enter the number 2: "
Read number2
sum=add(number1,number2)
Display "Sum = "+sum
else if ch=2 then
Display "You have chosen Subtraction!"
Display "Enter the number 1: "
Read number1
Display "Enter the number 2: "
Display number2
difference=sub(number1,number2)
Display "Difference = "+difference
else if ch=3 then
Display "You have chosen Multiplication!"
Display "Enter the number 1: "
Read number1
Display "Enter the number 2: "
Read number2
product=mult(number1,number2)
Display "Product = "+product
else if ch=4 then
Display "You have chosen Division!"
Display "Enter the number 1: "
Read number1
Display "Enter the number 2: "
Read number2
d=div(number1,number2)
Display "Quotient = "+div
else if ch=6
else
Display "Wrong menu item."
End if
Stop
Comments
Leave a comment