Create a logical calculator that takes a value, a basic operator (&,!,l,a) and all values from user input and have it print the result of the operation. The logical operations should be wrapped inside of functions.
#include<iostream>
using namespace std;
void calculator(int a,char b,int c){
if(b=='+'){cout<<a<<b<<c<<"="<<a+c<<endl;}
if(b=='-'){ cout<<a<<b<<c<<"="<<a-c<<endl; }
if(b=='X'){ cout<<a<<b<<c<<"="<<a*c<<endl; }
if(b=='/'){ cout<<a<<b<<c<<"="<<a/c<<endl; }
}
int main(){
char y='y';
int e,f;
char g;
while(y=='y' || y=='Y'){
cout<<"Enter first value "<<endl;
cin>>e;
cout<<"Enter operant "<<endl;
cin>>g;
cout<<"Enter second value "<<endl;
cin>>f;
calculator(e,g,f);
cout<<"press y to continue or any other letter to quit."<<endl;
cin>>y;
}
return 0;}
Comments
Leave a comment