password cracker problem from Jumping into C++

Hi everyone. came across this problem from loop chapter of jumping into C++. The problem is:

"Write a user login program that allows user to enter login info only certain number times so that user wouldn't write a password cracker"

everything seems right . but everytime I run it, in code::blocks(IDE for windows), in the build message window, I get the message. " undefined reference to 'WinMain@16' ".
i tried writing same code with all while, for- while, and do-while loop. but everytime the same message. could anyone tell what the problem is either with my IDE configuration or code. Also does anyone have more succint way of writing the same? (remember i am into c++ only for only 3 days. so i only know the concept of if and loops)

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(while loop)

  #include <iostream>
#include <string>
using namespace std;
int man()
{
    string user_name;
    string password;
    int x=1;
    while (x<6)
    {
        cout << "enter user name: ";
        getline (cin,user_name,'\n');
        cout << "enter password: ";
        getline (cin,password,'\n');
        if (user_name=="addictive"&&password=="programming")
        {
            cout << "Access allowed!\n";
            break;
        }
        x++;//check
        cout << "Wrong username or password! Try again! \n";

    }
}

2. (do-while loop)


#include <iostream>
#include <string>
using namespace std;
int man()
{
    string user_name;
    string password;
    int x=1;
    do
    {
        cout << "enter user name: ";
        getline(cin, user_name, '\n');
        cout<< "enter password: ";
        getline (cin, password, '\n');
        if (user_name=="gaurab"&&password=="4163")
        {
            cout << "Access allowed! \n";
            break;
        }
        cout << "Wrong user name or password. Try again!\n";
        x++;
    }while (x<6);
    
}


3. for while loop


#include <iostream>
#include <string>
using namespace std;
int man()
{
    string user_name;
    string password;
    for (int x=1;x<6;x++)
    {
        cout << "Enter user name: ";
        getline(cin, user_name, '\n');
        cout << "Enter password: ";
        getline (cin, password, '\n');
        if (user_name=="gaurab"&&password=="4163")
        {
            cout<< "Access allowed! ";
            break;
            
        }
        cout<< "Access denied! Try again! \n";
        
    }

}
The problem is, I think, with your IDE configuration (though you will want to rename int man() to int main()); your program apears to be set to build as a Windows application, which starts from WinMain() rather than main(). I suggest you make a new Empty Project and copy your code into there, then try building.
my bad in typing error. changing "int man()" to "int main()" solved the problem. everytime with new loop only changed the body and thus missed "int man()"
thank you for solution.
by the way could you plz have a look at this new problem?

http://www.cplusplus.com/forum/beginner/157904/

thanks again.

Last edited on
that is because you mispelled the main into man;


by the way that error only appears when you dont have your main function
Topic archived. No new replies allowed.