Trying to write an elementary calculator in C ++

#include <iostream> using namespace std; int main() { int a,b,d; char c; cout << "Enter first number " << endl; cin >> a; cout << "enter sing" << endl; cin >> c; cout << "Enter second number " << endl; cin >> b; switch (c) { case '+': d = a + b; break; case '-': d = a - b; break; case '*': d = a*b; break; case '/': d = a/b; break; } cout << "result = " << d; system ("pause >> void"); return 0; } 

But it gives 2 errors: LNK2005 and LNK1169 Please help 2-day programmer)

  • 2
    If you give a complete error message, it will be easier to guess what went wrong. Even among programmers with more experience, not everyone remembers the numerical error codes by heart. - VladD
  • (And yes, why are you redirecting the output of the pause command to a file called void ?) - VladD
  • one
    @VladD Good night. I'll try to think of something to come up with - 2ez4kot
  • one
    @VladD Yes! After rebooting, everything worked! Thank you very much! - 2ez4kot
  • one
    @Nik: This is understandable, but why should the message “press any key” be written to a file on disk with the name void ? - VladD

1 answer 1

Error messages LNK2005 and LNK1169, as suggested by Google, speak of re-defining a symbol (that is, violating the ODR rule). The exact error contains the name of the _main symbol, which is the decorated name (read somewhere, which needs name decoration when compiling) of the main function.

There is no second definition of main in the above code. This means that there is more code in the project. Thus, two options are possible.

  • Either the main function, as given in the question, is defined in the header, and this header is connected from several cpp files.
  • Either the main function is defined in the cpp-file, as it should, but there is another cpp-file with another main function.

Investigation in the comments showed that there is a second option. One of the main 's must be deleted, renamed, or at least commented out.