0

I recently started learning c++ basics and now getting familiar with "while" concept. I working on a code that will validate users pin code.Could some one tell me why is it happening?

#include<iostream>
using namespace std;

void Main()
{
    int pinUzytkownika=4567,pin,errorlicznik = 0;
    do{
        cout<<"PIN: ";
        cin >> pin;

     if(pin != pinUzytkownika)
     {
         errorlicznik++;

     }

    }while(errorlicznik<3 && pin!=pinUzytkownika);

    if(errorlicznik < 3)
    cout<<"Loading..";
    else
    cout<<"Blocked";


}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • ***why does my code sayserror: ld returned 1 exit status?*** This means you have some type of linker error. The actual description of the error should have been above the text you quoted. – drescherjm Feb 27 '22 at 15:04
  • 1
    `void Main()` is wrong. See [**What is the proper declaration of main in C++?**](https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main-in-c) – Andrew Henle Feb 27 '22 at 15:05
  • As a programmer it's very important that you make an attempt to understand what the compiler is trying to tell you. Many new people see an error message and instead of trying to understand the message they randomly change parts of their code. This is a very bad practice which will unlikely lead to success. Instead learn and understand what the compiler is telling you. – drescherjm Feb 27 '22 at 15:10
  • @drescherjm ok then i will study things in the question @AndrewHenle qouted above also this is the full message: X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main': C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status – Hubert457 Feb 27 '22 at 15:17
  • Because you used a wrong signature for the int main() function your linker did not find your main() so it attempted to link to WinMain() (used only in a windows GUI appilcation) which it did not find. As a result of having no main function the linker then told you it could not create your executable and ended. Also note that `c++` is case sensitive. int Main() is different from int main(). I said `int main()` because `void main()` is also wrong and has not been valid in c++ for a long time although Visual Studio allowed you to use it anyways to not error on old code. – drescherjm Feb 27 '22 at 15:22
  • The duplicate should explain the valid forms of main() – drescherjm Feb 27 '22 at 15:25
  • 1
    @drescherjm I corrected it and now everything works i didnt know that void main() is not valid. thank you so much! – Hubert457 Feb 27 '22 at 15:31

0 Answers0