0% found this document useful (0 votes)
54 views

Calculation On C++

This C++ program defines functions for performing basic mathematical operations: addition, subtraction, multiplication, division, modulus, and factorial. The main function displays a menu asking the user to select an operation, calls the corresponding function, and returns the result. Each function prompts the user to input numbers, performs the selected operation, and displays the output.

Uploaded by

Benita Agbagwara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Calculation On C++

This C++ program defines functions for performing basic mathematical operations: addition, subtraction, multiplication, division, modulus, and factorial. The main function displays a menu asking the user to select an operation, calls the corresponding function, and returns the result. Each function prompts the user to input numbers, performs the selected operation, and displays the output.

Uploaded by

Benita Agbagwara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


int add ()
{
float a, b;
cout <<"Input the two numbers: \n";
cin >> a >> b;
float c = a+b;
cout<< "The sum is: " << c<< endl;
return 0;
}
int sub ()
{
float d,e;
cout << "input the first and second number: \n";
cin >> d >> e;
float f = d-e ;
cout << "The difference is: "<< f<< endl;
return 0;
}
int product ()
{
float g,h;
cout<< "Input the two numbers: \n";
cin>> g >> h;
float i = g*h;
cout<<"The product is : " << i<< endl;
return 0;
}
int division ()
{
float j,k;
cout<< "Input the first and second number: \n";
cin>>j >>k;
float l = j/k ;
cout<<"The division is : " <<l << endl;
return 0;
}
int mod()
{
int m, n;
cout <<"Input the first and second number: \n";
cin >> m >> n;
int o = (m % n );
cout << "The modulus is : " << o<< endl ;
return 0;
}
int factorial()
{
int p,q,r;
r = 1;
cout<<"Enter the number : ";
cin >> p;
{
if( p != 0)
{
for (q= p; q>0 ; q--)
{
r *= q;
}
cout<< "The factorial is : "<< r<< endl;
}
else
{
cout<<"Math error! \n";
}

}
return 0;
}

int main()
{
int option;
cout<<"\nThanks for using our calculator\n" <<"What would you like to do? \n"
<< 1 <<"> Addition \n" << 2<< "> Subtraction \n" << 3 << "> Multiplication \n"
<< 4<< "> Division \n" << 5 << "> Modulus\n"
<< 6 << "> Factorial \n" << 7 << "> Nothing\n" <<"Enter your option: ";
cin >> option;

switch (option)
{
case 1 :
add();
break;

case 2 :
sub ();
break;

case 3 :
product ();
break;

case 4 :
division ();
break;

case 5 :
mod();
break;

case 6:
factorial();
break;

case 7:
cout<<"Okay byeee.\n";
break;

default:
cout<<"You have entered the wrong option! \n" <<"Goodbye.\n";

return 0;
}

You might also like