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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <cstdlib>
#include <iostream>

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.