0

I'm new to C++. I tried to compile this on a Mac in Terminal using gcc, but I got the symbols not found, along with a linker error. What seems to be the problem here? Thanks in advance!

# include <iostream>
using namespace std;

int main(int argc, char *argv[]) {

    char o;
    float num1, num2;
    cout << "Enter operator either + or - or * or /";
    cin >> o;
    cout << "Enter two operands: ";
    cin >> num1 >> num2;

    switch(o) {
            case '+':
                    cout << num1+num2;
                    break;
            case '-':
                    cout << num2-num1;
                    break;
            case '*':
                    cout << num1*num2;
                    break;
            case '/':
                    cout << num1*num2;

                    break;
            default:
                    cout << "Error, operator is not correct";
                    break;
    }
return 0;

}

1 Answers1

0

Well, I just used "g++" on MacOSX 10.10.5 and it compiled first time. PS: You might want to add a newline to the output ;)

BigGray% g++ t.cpp -o t
BigGray% ./t
Enter operator either + or - or * or /+
Enter two operands: 1 3
4%                                                                                                                                                                                                    BigGray% g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
BigGray% uname -a
Darwin BigGray.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
BigGray%
Hvisage
  • 266
  • 2
  • 9