Question

Create a C++ calculator that allows you to add, multiply, divide, or subtract, and allows you...

Create a C++ calculator that allows you to add, multiply, divide, or subtract, and allows you to inlcude an infinite amount of inputted numbers for it.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;

int main()
{

long num;
long mult=1;
long sum=0;
long sub=0;
char ch;

cout<<"Menu options: "<<endl;
cout<<"--------------------------------------"<<endl;
cout<<"1. Addition"<<endl;
cout<<"2. Subtraction"<<endl;
cout<<"3. Multiplication"<<endl;
cout<<"4. Division"<<endl;
cout<<"--------------------------------------"<<endl<<endl;


while(1)
{
  
int choice;
cout<<"Enter Your choice: ";
cin>>choice;
  
switch(choice)
{
case 1:

while(1)
{
cout<<"Enter a value: ";
cin>>num;
sum=sum+num;
cout<<"Do you want to add another number (y/n): ";
cin>>ch;
if(ch=='N' || ch=='n')
{
break;
}
}
cout<<"Addition of all entered numbers: "<<sum<<endl;
break;

case 2:
long num1,num2;
while(1)
{
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
sub=num1-num2;
cout<<"Subtraction: "<<sub<<endl;
cout<<"Do you want to take another two numbers (y/n): ";
cin>>ch;
if(ch=='N' || ch=='n')
{
break;
}
}
break;

case 3:
while(1)
{
cout<<"Enter a value: ";
cin>>num;
mult=mult*num;
cout<<"Do you want to add another number (y/n): ";
cin>>ch;
if(ch=='N' || ch=='n')
{
break;
}
}
cout<<"Multiplication of all entered numbers: "<<mult<<endl;
break;

case 4:
long dividend,divisor;
double div;
while(1)
{
cout<<"Enter Dividend: ";
cin>>dividend;
cout<<"Enter Divisor: ";
cin>>divisor;

div=(double)dividend/divisor;
cout<<"Division: "<<div<<endl;
cout<<"Do you want to add next two numbers(dividend,divisor) (y/n): ";
cin>>ch;
if(ch=='N' || ch=='n')
{
break;
}
}
break;

default:
cout<<"Invalid option!!";
break;
}
cout<<"\n\nDo you want to perform another operation (y/n): ";
cin>>ch;
if(ch=='N' || ch=='n')
{
break;
}
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Create a C++ calculator that allows you to add, multiply, divide, or subtract, and allows you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT