April 7, 2025

A code for Simple Calculator with Switch statement

 





#include <iostream>
#include <string>
using namespace std;
int main (){

// decision making

int n1, n2;
char op;

cout<< "Enter your 2 number" <<endl;
cin>>n1 >>n2;
cout<<"Enter your operand"<<endl;
cin>>op;

switch (op)
{
case '+':
cout<<n1+n2<<endl;
break;
case '-':
cout<<n1-n2<<endl;
break;

case '*':
cout<<n1*n2<<endl;
break;

case '/':
cout<<n1/n2<<endl;
break;

case '%':
cout<<n1%n2<<endl;
break;


default:cout<<"not valid"<<endl;
break;
}



return 0;
}
Tags:

Post a Comment

Post a Comment

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

Author Name

Contact Form

Name

Email *

Message *

Powered by Blogger.