Why am i getting this error

I keep getting this error :ambiguous overload for 'operator>>' in 'std::cin >> O' on line 42

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

using namespace std;

int main()
{
    {
         double firstNumber = 0.0;
         double secondNumber = 0.0;
         char operation =' ';
         char doAgain=' ';
do
{
     cout << "welcome to Calculator++." << endl;
     cout << "Select Operation" << endl;
     cout << "1. Basic calculations" << endl;
     cout << "2. Trigonometry" << endl;
     cout << "3. Statistics" << endl;

    int M;
    cin >> M;

     if ( M == 1 ){
        cout << "1. Addition" << endl;
        cout << "2. Subtraction" << endl;
        cout << "3. Multiplication" << endl;
        cout << "4. Division" << endl;
        cout << "5. Square a number" << endl;
        cout << "6. Cube a number" <<endl;
        cout << "7. X to the power of N" <<endl;
        cout << "8. Squareroot" <<endl;

        {
                cout << "Enter first number" <<endl;
                cin>>firstNumber;
                cout << "Enter operation number (1 to 8)" <<endl;
                cin>>operation;
                cout << "Enter second number" <<endl;
                cin>>secondNumber;

                int O();
                cin >> O;

                if ( O == 1 ) {
                    cout << "the answer is..."<<firstNumber<<"+"<<secondNumber<<"="<<(firstNumber+secondNumber)<<endl;
                    break;
                }

                if ( O == 2){
                    cout << "the answer is..."<<firstNumber<<"-"<<secondNumber<<"="<<(firstNumber-secondNumber)<<endl;
                    break;
                }
int O();

What are the parentheses for? Get rid of those and it should work.
1
2
// int O() ; // this is the declaration of a function
int O ;


And don't use a name like O; far too easy to misread it as a zero.

If it must be initialized: int O = 0 ; or int O {} ;

Last edited on
thanks freddy92, and good advice JLBorges. Im quite new to programming but i naturally try really complicated things. Like with this calculator im writing, im hoping to be able to use it to calculate the PMCC thats normally in the Statistics modules of A-Level maths.
Topic archived. No new replies allowed.