Write a program that lets the user perform arithmetic operations on two numbers. Your program must be menu driven, allowing the use to select the operation (+, -, *, or /) and input the numbers.
Furthermore, your program must consist of following functions:
- Function show Choice: This function shows the options to the user and explains how to enter data.
- Function add: This function accepts two number as arguments and returns sum.
- Function subtract: This function accepts two number as arguments and returns their difference.
- Function multiply: This function accepts two number as arguments and returns product.
- Function divide: This function accepts two number as arguments and returns quotient
Program
#include <iostream> #include <conio.h> #include<string.h> using namespace std; char showmanue() { char operand; cout<<"(a) choice for sum"; cout<<"\n(b) choice for sub"; cout<<"\n(c) choice for mul"; cout<<"\n(d) choice div"; cout<<"enter the operand"; cin>>operand; return operand; } int sum(int a,int b) { int sum; cout<<"enter the a"; cin>>a; cout<<"enter the b"; cin>>b; sum= a+b; cout<<sum; } int sub(int a,int b) { int sub; cout<<"enter the a"; cin>>a; cout<<"enter the b"; cin>>b; sub= a-b; cout<<sub; } int mul(int a,int b) { int mul; cout<<"enter the a"; cin>>a; cout<<"enter the b"; cin>>b; mul= a*b; cout<<mul; } int div(int a,int b) { int div; cout<<"enter the a"; cin>>a; cout<<"enter the b"; cin>>b; div= a/b; cout<<div; } int main() { char ret; ret=showmanue(); if (ret=='+') { int a,b; sum(a,b); } else if (ret=='-') { int a,b; sub(a,b); } else if (ret=='*') { int a,b; mul(a,b); } else if (ret=='/') { int a,b; div(a,b); } }
Post A Comment:
0 comments: