Answer to Question #191107 in C++ for python

Question #191107

Make a calculator using if-else-if else statement which perform the addition, subtraction, multiplication, division and remainder operations. Take values and operator from user on runtime. Use do while loop for user choice. Means after performing one operation program will ask from user “do you want to do another calculation(yes/no)? ”. If user press then user will enter number 1, number 2 and operator for calculation and if user press no then terminate the loop.



1
Expert's answer
2021-05-09T14:43:57-0400
#include <iostream>


using namespace std;
int main(){
    int num1,num2;
    char op;


    do{
      cout<<"Enter the first number: ";
      cin>>num1;
      cout<<"Enter the second number: ";
      cin>>num2;
      cout<<"Enter the operation: ";
      cin>>op;


      if (op=='+')
        {
        cout<<num1<<" + "<<num2<<" = "<<num1+num2;
        }
      else if (op=='-')
        {
        cout<<num1<<" - "<<num2<<" = "<<num1-num2;
        }
      else if (op=='*')
        {
        cout<<num1<<" * "<<num2<<" = "<<num1*num2;
        }
      else if (op=='/')
        {
        cout<<num1<<" / "<<num2<<" = "<<num1/num2;
        }
      else if (op=='%')
        {
        cout<<num1<<" % "<<num2<<" = "<<num1%num2;
        }
      else{
        cout<<"\nInvalid Operation"<<endl;
      }


      string choice;
      cout<<"\n Do you want to do another calculation(yes/no)?";
      cin>>choice;
      if (choice=="yes"){
        continue;
      }
      else if(choice=="no"){
        break;
      }
    }
    while(true);
    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