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

C++ Calculator Submitted To - Mr. Manas Submitted by - Jitendra XIA

This C++ program defines a function called calc() that takes in two integers and an arithmetic operator as arguments. It uses a switch statement to perform the calculation based on the operator passed and prints out the result. The main() function gets the two numbers and operator from the user, calls the calc() function, and returns the result.

Uploaded by

Jitendra Chauhan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

C++ Calculator Submitted To - Mr. Manas Submitted by - Jitendra XIA

This C++ program defines a function called calc() that takes in two integers and an arithmetic operator as arguments. It uses a switch statement to perform the calculation based on the operator passed and prints out the result. The main() function gets the two numbers and operator from the user, calls the calc() function, and returns the result.

Uploaded by

Jitendra Chauhan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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