Calculator using Switch Case
Here you will learn to make a Calculator using Switch Case in CPP programming. This is a basic calculator that perform the Addition, Subtraction, Multiplication, and Division calculations.
Example to Create Calculator using Switch Case in CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include<iostream> using namespace std; int main() { float num1, num2, result; int ch; cout<<"\n Simple Calculator for the following calculations \n"; cout<<" 1. Addition\n"; cout<<" 2. Subtraction\n"; cout<<" 3. Multiplication\n"; cout<<" 4. Division\n"; cout<<" 5. Exit\n\n\n"; cout<<" Enter Your Choice(1-5): "; cin>>ch; if(ch>=1 && ch<=4) { cout<<"\n Enter two Numbers: "; cin>>num1>>num2; } switch(ch) { case 1: result = num1+num2; cout<<"\n Result = "<<result; break; case 2: result = num1-num2; cout<<"\n Result = "<<result; break; case 3: result = num1*num2; cout<<"\n Result = "<<result; break; case 4: result = num1/num2; cout<<"\n Result = "<<result; break; case 5: return 0; default: cout<<"\n Wrong Choice!"; break; } cout<<"\n*********************************\n"; return 0; } |
Output
Check out our other C++ programming Examples