no match for 'operator==' in 'operation == addition'?

I am creating a simple calculator with all operations, but it's not working!
Here is my code:

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
//The Calculator
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int addition(float a, int b)
{
    float result;
    result = a+b;
    return result;
}

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

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

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

int remainder(float a, float b)
{
    float result;
    result = a*b;
    return result;
}


int main()
{
    cout << "Which operation do you want to calculate? There is addition, subtraction, multiplication, division and remainder.";
    string operation;
    getline(cin,operation);
    if (operation == addition)
        cout << "You chosen addition.";

    else if (operation == subtraction)
        cout << "You chosen subtraction";

    else if (operation == multiplication)
        cout << "You chosen multiplication.";

    else if (operation == division)
        cout << "You chosen division.";

    else if (operation == remainder)
        cout << "You chosen to find the remainder.";

    else
        cout << "You typed something else. Terminating program...";
        return 0;
}


I even tried using type instead of operation. It pops up with this error message:
no match for 'operator==' in 'operation == addition'
What is wrong with this code and what can I do to fix it?
Last edited on
You can't compare a string with a function.

I would recommend you make a menu instead. Then using if statements or a switch case, you can determine what the user chose.

1
2
int choice;
cin >> choice;


Present menu:
1. Addition
2. Multiplication
3. Subtraction
4. Division
1
2
if(choice == 1)
    cout << "You chose Addition";
What is addition here?
if (operation == addition)

You could try
 
    if (operation == "addition")
though as an end-user of a calculator, I'd prefer a single character such as
 
    if (operation == "+")


Last edited on
Thanks, Tarik!
Topic archived. No new replies allowed.