Answer to Question #155263 in C++ for LEEYAH

Question #155263

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.


1
Expert's answer
2021-01-13T08:18:01-0500


#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;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog