Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Submitted To Mr.

Manas Submitted Calculator C++ By Jitendra XI A

Write
result.

a C++ program that invokes a function calc( ) which intakes

two integers and an arithmetic operator and prints the corresponding

#include<iostream.h> #include<conio.h> #include<process.h> int main( ) { clrscr( ); void calc(int x, int y, char c); int a, b; char ch; cout << Welcome to C++ Calculator <<endl; cout << This Program is for making your calculation in Easier way <<endl; cout << Enter any two integers : \n; cin >> a >> b; cout << \n Enter an arithmetic operator (+, -, *, /, %) : \n; cout << 1. + for Addition <<endl; cout << 2. - for Subtraction <<endl; cout << 3. * for Multiplication <<endl; cout << 4. / for Division <<endl; cout << 5. % for Modulus/Remainder <<endl; cin >> ch; calc(a, b, ch);

return 0; } void calc(int x, int y, char c) { switch(c) { case + : cout << \n Sum of << x << and << y << is << (x + y); break; case - : cout << \n Difference of << x << and << y << is << (x - y); break; case * : cout << \n Product of << x << and << y << is << (x * y); break; case / : if(x < y) { cout << \n First integer should be << greater than second.; exit(0); } cout << \n Quotient : << x << / << y << is << (x / y); break; case % : if(x < y) { cout << \n First integer should be << greater then second.; exit(0);

} cout << \n Remainder : << x <<% << y << is << (x % y); break; default : cout << \n Wrong Operator !!!; break; } return; }

You might also like