C++ Snippets

/*C++ Program that contains four user defined function(s) addition(), subtraction(),
division(), multiplication(). Develop a calculator as follows:
• In main() function:
o A menu with choices addition,subtraction,division and multiplication must be
displayed.
o Get two numbers and a choice from user o Call the respective functions with
user given number as parameter using switch statement
o Print the result from addition(), subtraction, division(), multiplication().
• In user defined functions:
o Plus and Minus function get two interger values and return interger.
o Multiply and Divide functions get two interge values and return float.*/
#include<iostream>
using namespace std;
int add(int x,int y);
int sub(int x,int y);
float mul(float x,float y);
float divi(float x,float y);
int main()
{
float a,b;
cout<<"\n\t\tEnter the First Integer :";
cin>>a;
cout<<"\n\t\tEnter the Second Integer :";
cin>>b;
add(a,b);
cout<<endl;
sub(a,b);
cout<<endl;
mul(a,b);
cout<<endl;
divi(a,b);
cout<<endl;
}
int add(int x,int y)
{
cout<<"\n Addition is: "<< x+y;
}
int sub(int x,int y)
{
cout<<"\n Subtraction is: "<<x-y;
}
float mul(float x,float y)
{
cout<<"\n Multiplication is: "<< x*y;
}
float divi(float x,float y)
{
cout<<"\n Division is: "<<x / y;
}
Try using code tags:

1
2
3
4
void main
{
printf ("Hello World");
}
@Osmx99, Unless you have a question, please don't post your trash here.
Topic archived. No new replies allowed.