Write a program to work like a calculator that perform the addition, subtraction, multiplication and division operation. Your program should use the function call method to call four sub functions to do the arithmetic operations. Example of output:
cout << sum(6,2) << end1 //will print 8
cout << subtract(6,2) << end1 //will print 4
cout << multiply(6,2) << end1 //will print 12
cout << divide(6,2) << end1 //will print 3
#include <iostream>
using namespace std;
int sum(int a, int b){
return a + b;
}
int subtract(int a, int b){
return a - b;
}
int multiply(int a, int b){
return a * b;
}
float divide (int a, int b){
return a / b ;
}
int main()
{
cout << sum(6,2) <<endl; //will print 8
cout << subtract(6,2) << endl; //will print 4
cout << multiply(6,2) << endl; //will print 12
cout << divide(6,2) << endl; //will print 3
return 0;
}
Comments
Leave a comment