Answer to Question #191182 in C++ for python

Question #191182

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-15T13:46:51-0400
#include <iostream>
#include <string>
using namespace std;


int main(){
	int number1;
	int number2;
	int result;
	string operation;
	string answer="yes";
	while(answer=="yes"){
		cout<<"Enter number 1: ";
		cin>>number1;
		cout<<"Enter number 2: ";
		cin>>number2;
		cin.ignore();
		//addition, subtraction, multiplication, division and remainder
		cout<<"Select operation +, -, *, /, % : ";
		getline(cin,operation);
		if(operation=="+"){
			result=number1+number2;
			cout<<number1<<" + "<<number2<<" = "<<result<<"\n\n";
		}
		if(operation=="-"){
			result=number1-number2;
			cout<<number1<<" - "<<number2<<" = "<<result<<"\n\n";
		}
		if(operation=="*"){
			result=number1*number2;
			cout<<number1<<" * "<<number2<<" = "<<result<<"\n\n";
		}
		if(operation=="/"){
			double division=(double)number1/(double)number2;
			cout<<number1<<" / "<<number2<<" = "<<division<<"\n\n";
		}
		if(operation=="%"){
			result=number1%number2;
			cout<<number1<<" % "<<number2<<" = "<<result<<"\n\n";
		}
		cout<<"Do you want to do another calculation(yes/no)?: ";
		getline(cin,answer);
		if(answer=="yes"){


		}
	}




	system("pause");
	return 0;


}


Example:



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