### How to create a calculator that does +,-,*, and /?

I learned how to create a calculator that adds numbers, but that is all it does. I want to create a calculator that can add, subtract, multiply, and divide, but I just don't know how to do that. Is there a code for that, or is it impossible?
Thank you.

It's definitely possible. Ever used, say, the Windows Calculator? Same thing, just with a prettier UI.
http://www.cplusplus.com/forum/general/104457/#msg563157

Using sscanf, you can implement some "regex" to help identify symbols
gl
Really simple. All you need is a cin >> choice followed by a switch case or bunch of if statements.

Example:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` `````` #include #include using namespace std; int main() { int choice; int number1, number2; cout << "Choose your operation. \n "; cout <<"1 = Addition \n" ; cout <<"2 = Subtraction \n" ; cout <<"3 = Multiplication \n" ; cout <<"4 = Division \n "; cout <<"0 = EXIT \n \n"; cout << "Choice : "; cin >> choice; switch(choice) case 1: //Addition cout << "You are Adding. Enter a number you would like to add. \n Number 1: "; cin >> number1; cout << " Enter a second number. \n Number 2: "; cin >> number2; cout << " The answer is: "<< number1 + number2 << endl; cin.get() //This is used to pause the program break; case 2: //subtraction... ect. break; case 3: //multiply... break; case 4: //divide... break; } ``````

This is just an example though. Im sure that there are many ways to clean it up, and if i missed anything i apologize. Case 2, 3 and 4 are basically the same as 1, just using different operators. You could also use a loop to keep the program going until you quit. Hope this helps.

Are you asking for help in creating a windowed calculator or a calculator that only works in console like the code that dray 0 posted?
Topic archived. No new replies allowed.