If Statement problem

I have been programming for 2 days i have run in too a problem that i can not solve. It has put my learning on halt for hours. I have an if statement and i am getting an error about an ==. Here is the code so far:

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>

using namespace std;

int subtraction (int a, int b)
{
    int d;
    
    d = a - b;
    
    return d;
}

int addition (int a, int b) //i discovered you can use and b for all the functions
{                           //because they do not function together
    int s;
    
    s = a + b;
    
    return s;
}

int multiplication (int a, int b)
{
    int p;
    
    p = a * b;
    
    return p;
}

int division (int a, int b)
{
    int r;
    
    r = a / b;
    
    return r;
}

int main ()
{
    //variables
    int a;
    int b;
    string x;
    
    cout << "Lets do math!";
    cin.get();
    cout << endl << "These are the available operations:";
    cout << endl;
    cout << endl << "Addition";
    cout << endl << "Subtraction";
    cout << endl << "Multiplication";
    cout << endl << "Division";
    cin.get();
    cout << endl << endl << "Which operation would you like to use: ";
    cin >> x;
    
    if (x == addition)
    {
       cout << "You have chosen Addition!" << endl;
       cout << endl << "First number: ";
       cin >> a;
       cout << endl << "Second number: ";
       cin >> b;
       cout << endl << "Sum: " << addition (a,b);
       cin.get();
       cin.get();
    }
    
    else if (x == subtraction)
     {
       cout << "You have chosen Subtraction!" << endl;
       cout << endl << "First number: ";
       cin >> a;
       cout << endl << "Second number: ";
       cin >> b;
       cout << endl << "Difference: " << addition (a,b);
       cin.get();
       cin.get();
    }
    
    return 0;
}


Here is the error: 61 no match for 'operator==' in 'x == addition'
You have to put "" around string literals:
if (x == "addition")
It's always the little things! Thanks a lot!
also, nobody wants to type their choice as text, it's better to put just numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
    ....
    int choice =0;
    ...
    cout << endl << "1. Addition";
    cout << endl << "2. Subtraction";
    cout << endl << "3. Multiplication";
    cout << endl << "4. Division";
       cout << endl << endl << "Which operation would you like to use: ";
    cin >> choice;
    
    if (x == 1)
    {
  ......

Topic archived. No new replies allowed.