compiler error for function that works four other times

compile error is coming on lines 7 and 32 twice, both being the same complaint.
line 7; candidates are: void minus(float, float, float)
line 32; reference to 'minus' is ambiguous.

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
#include <iostream>

using namespace std;

void add(float first_num, float second_num, float answer);

void minus(float first_num, float second_num, float answer);

void times(float first_num, float second_num, float answer);

void divide(float first_num, float second_num, float answer);

int main()
{
    float first_num;
    float second_num;
    int x;
    float answer;
    cout << "please enter first number";
    cin >> first_num;
    cout << "please enter second number";
    cin >> second_num;
    cout << " please enter 1, 2, 3 or 4 for the mathematical operator + - * or / correspondinly";
    cin >> x;
    switch (x)
    {
        case '1':
            add(first_num, second_num, answer);
        break;

        case '2':
            minus(first_num, second_num, answer);
        break;

        case '3':
            times(first_num, second_num, answer);
        break;

        case '4':
            divide(first_num, second_num, answer);
        break;

        default:
            cout << "number entered incorrectly";
            return 0;
    }
     return 0;
}

void minus(float first_num, float second_num, float answer)
{
    first_num - second_num == answer;
    cout << answer;
}
...
Last edited on
minus already exists in C++. What happens if you rename it?
didn't know, thankyou.

that was driving me up the wall!
This is your problem:
 
using namespace std;

It is best not to use that because it can introduce hard to find bugs. The problem is that std::minus() is already defined in the standard library. When you say: using namespace std; you move its declaration into the global namespace, so it clashes with your own minus() function.

http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5

http://www.cplusplus.com/reference/std/functional/minus/
Use a namespace, or change the name of the function.

Also, c++ is not prolog. first_num - second_num == answer; statement has no effect.
thanks guys, taken that to heart.

its now all working xD

much appreciated
Topic archived. No new replies allowed.