Its Got Linker Errors!

I am just new to c++ prog but i did this as my project with help
the problem i am having is a linker error so if anyone could solve it it would help
THANKS
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <iostream.h>
#include <conio.h>
#include<fstream.h>
#include <process.h>
int main()
{
int ch;
char x;

do
{
     cout <<"Hello And Welcome To Dsz Cinemas\n";
     cout <<"Please Type In The Number Of Your Choice\n";
     cout <<"1. Booking Tickets\n";
     cout <<"2. Latest Updates\n";
     cout <<"3. Gold Membership\n";          //prob is in this selection
     cout <<"4. Credits\n";
     cin >>ch;
     system("cls");
     
     if (ch==3) //must put the login info under here
     {
         cout <<"Welcome to our gold membership\n";
                using namespace std;
                void Auth();
                void Members();
                void Userchange();
                void Passchange();
                
                string inuser;
                string inpass;
                string user;
                int num = 0;
                int ch;
                char pass[BUFSIZ];
                int i = 0;
                string com;
                
                main();
                {
                       system("cls");
                       cout<<"Welcome\n---------------------------\n\n";
                       while(num==0)
                       {
                                    system("cls");
                                    cout<<"Command: ";
                                    cin>>com;
                                    if(com=="login")
                                    {
                                                    Auth();
                                    }
                                    else if(com=="change-pass")
                       {
                                    Passchange();
                       }
                       else if(com=="change-user")
                {
                       Userchange();
                }
                else if(com==com)
                {
                     cout<<"Unknown command\n";
                     }
                }
     }
     void Auth();
     {
          ifstream Passfile("password.txt", ios::in);
          Passfile>>inpass;
          ifstream Userfile("username.txt", ios::in);
          Userfile>>inuser;
          system("cls");
          cout<<"USERNAME: ";
          cin>>user;
          cout<<"PASSWORD: ";
          fflush(stdout);
          
          while ((ch = getch()) != EOF 
          && ch != '\n' 
          && ch != '\r' 
          && i < sizeof(pass) - 1)
          {
               if (ch == '\b' && i > 0) 
               {
                      printf("\b \b");
                      fflush(stdout);
                      i--;
                      pass[i] = '\0';
                      }
                      else if (isalnum(ch))
                      {
                           putchar('*');
                           pass[i++] = (char)ch;
                      }
               }
               pass[i] = '\0';
               Userfile.close();
               Passfile.close();
               if(user==inuser&&pass==inpass)
               {
                            Members();
               }
                            else
               {
                            cout<<"nope";
                            getch();
                            main();
                            }
               }
               void Userchange();
               {
                    string tempass;
                    system("cls");
                    cout<<"enter current password: ";
                    cin>>tempass;
                    if(tempass==inpass)
                    {
                                       cout<<"utility to change username stored in file\n";
                                       cout<<"CHANGE USER TO: ";
                                       cin>>user;
                                       ofstream Userfile("username.txt", ios::out);
                                       Userfile<<user;
                                       Userfile.close();
                                       cout<<"Username successfully changed";
                                       getch();
                                       main();
                    }
                                       else
                                       {
                                           cout<<"Invalid Password";
                                           getch();
                                           main();
                                       }
                    }
                    void Passchange();
                    {
                         string pass;
                         system("cls");
                         cout<<"enter current password: ";
                         fflush(stdout);
                         while ((ch = getch()) != EOF 
                         && ch != '\n' 
                         && ch != '\r' 
                         && i < sizeof(pass) - 1)
                         {
                              if (ch == '\b' && i > 0) 
                              {
                                     printf("\b \b");
                                     fflush(stdout);
                                     i--;
                                     pass[i] = '\0';
                                     }
                                     else if (isalnum(ch))
                                     {
                                          putchar('*');
                                          pass[i++] = (char)ch;
                                     }
                              }
                              pass[i] = '\0';
                              if(pass==inpass)
                              {
                                              cout<<"utility to change password stored in file\n";
                                              cout<<"CHANGE PASS TO: ";
                                              cin>>user;
                                              ofstream Passfile("password.txt", ios::out);
                                              Passfile<<user;
                                              Passfile.close();
                                              cout<<"password successfully changed";
                                              getch();
                                              main();
                              }
                                              else
                                              {
                                                  cout<<"Invalid Password: ";
                                                  getch();
                                                  main();
                                              }
                         }
                         void Members();
                         {
                              system ("cls");
                              cout <<"wassup";
                              cout<<"nothing";
                              getch ();// put members code here
                              // like a while(){} loop or somethin like that
                              // comment please
                         }
                         
}


else if (ch>4)
     cout <<"The number typed in is wrong Dum Dum =P\n\n\n\n";
     
     
     cout<<"\n\nDo you wish to redo your selection and select another option or exit? (Y/N)\n";
     cin>>x;
     system("cls");
}
while (x=='Y'||x=='y');
cout <<"Thankyou for choosing Dsz Cinemas!!!\nSorry for any inconvenience\nHope to see you again ^.^ :D\nBye"; 
getch();
exit(0);

getch();
}
What is the error?
it say cannot link
[Linker error] undefined reference to `Auth()'
[Linker error] undefined reference to `Passchange()'
[Linker error] undefined reference to `Userchange()'
[Linker error] undefined reference to `Members()'
im new to c++
i got this code from elsewhere!
so could u show me an example?
You cannot define functions inside other function, that is you cannot define
Auth, Passchange, Userchange, Mebers functions inside main function. You should define them outside of main, then call them from main.
+1 for TTT.
You should puth the Auth function outside (on top of main) and remove the semicolons after their names.
Like:

1
2
3
4
5
6
void YourFunction() {
    // Do Something
}
int main() {
    YourFunction();
}
could u take just one part of the program and do it and show me
It would b of big help tanks
When adding a new function yu have three seperate and very important steps. You have to forward declare the function, invoke it and define it. At the moment your program is invoking and defining the functions but not forward declaring them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using std::cout;
using std::endl;

//forward declaration
void MostAwesomeFunction();

int main()
{
   //invokation
   MostAwesomeFunction();
}

//function definition
MostAwesomeFunction()
{
   cout << "This is such an awesome function!" << endl;
}


The main function is the starting point for any and all c++ programs and so does not need to be invoked or forward declared, you just define it. Also it is bad practise to invoke the main function as you have in your program. Instead use techniques to control the flow of the progam such as conditional statements and loops.

Since this is such a basic concept I suggest you read up and practise using functions in your programs and then come back to this example and try and fix it yourself.
Last edited on
Topic archived. No new replies allowed.