Help with fakelogin

I am reading a book in c++ programming, but i cant get this code to work.
i am making a fakelogin in microsoft visual C++ 2008 express edition.
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
 #include "stdafx.h"
#include <iostream>
#include "windows.h"
using namespace std;

bool login ( User*, char* Pass)
{
	<<cout"Enter Username: ";
	cin>>User;
	_stupr(User);
	cout<<"Enter Password: ";
	cin<<Pass;
	_stupr(Pass);
	int x=0;
	while (x<30)
	{
		cout<<"."<< flush;
		Sleep(100);
		++x;
	}
	cout<<endl;
	if (strcmp (User, "AGENT"==0)
	{
		if (strcmp (Pass, "AGENT01"==0)
		{
			return true;
		}
	}
return false;
}

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

{
	char(User)[100];
	char(Pass)[100];
	bool LoginOk;
	LoginOk=Login(User, Pass);
	if LoginOk== true )
	{
		cout<<"Acces granted for "
			<<User<<"."<<endl;
	}
	else
	{
		cout<<"Acess Denied..."<<endl;
	}
	Sleep(3000);

	return 0;

}
And your issue is?
It doesnt compile. getting errors listed under here:

1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(38) : error C3861: 'Login': identifier not found
1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(39) : error C2061: syntax error : identifier 'LoginOk'
1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(39) : error C2059: syntax error : ')'
1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(40) : error C2143: syntax error : missing ';' before '{'
1>c:\users\rickard\documents\visual studio 2008\projects\fakelogin\fakelogin\fakelogin.cpp(44) : error C2181: illegal else without matching if
1>Build log was saved at "file://c:\Users\Rickard\Documents\Visual Studio 2008\Projects\Fakelogin\Fakelogin\Debug\BuildLog.htm"
1>Fakelogin - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
line 8: cout should be before the << operator.

line 22: add another brace
if(strcmp(Pass,"AGENT")==0)
same in line 24.

as far as i know, the function Sleep() exists in the real Windows.h, try _sleep().
Thanks for the help, however it did not solve anything.
I appreciate that you were trying.
See the edits I made (commented).

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
#include "stdafx.h"
#include <iostream>
#include "windows.h"
using namespace std;

bool login ( char* User, char* Pass) //need type for user
{
	cout<<"Enter Username: "; //ostream AFTER cout
	cin>>User;
	_stupr(User);
	cout<<"Enter Password: ";
	cin>>Pass; //wrong operator... NOT <<
	_stupr(Pass);
	int x=0;
	while (x<30)
	{
		cout<<"."<< flush;
		Sleep(100);
		++x;
	}
	cout<<endl;
	if (strcmp (User, "AGENT")==0) //missing ) after "AGENT"
	{
		if (strcmp (Pass, "AGENT01")==0) //missing ) after "AGENT01"
		{
			return true;
		}
	}
return false;
}

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

{
	char(User)[100];
	char(Pass)[100];
	bool LoginOk;
	LoginOk=login(User, Pass); //login should be lowercase
	if (LoginOk== true ) //missing ( before LoginOk
	{
		cout<<"Acces granted for "
			<<User<<"."<<endl;
	}
	else
	{
		cout<<"Acess Denied..."<<endl;
	}
	Sleep(3000);

	return 0;

}
Last edited on
fixed it.
thanks Metal Militia for all the help.
changes i did.

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
#include "stdafx.h"
#include <iostream>
#include <string.h> // Forgot to include the string.h file.
#include "windows.h"
using namespace std;

bool Login ( char* User, char* Pass) // Forgot a "char*" before "User".
{
	cout<<"Enter Username: ";
	cin>>User;
	_strupr(User);
	cout<<"Enter Password: ";
	cin>>Pass;
	_strupr(Pass);
	int x=0;
	while (x<30)
	{
		cout<<"."<< flush;
		Sleep(100);
		++x;     // or x=x+1 if you want to.
	}
	cout<<endl;
	if (strcmp (User, "AGENT")==0) // forgot to add ')' after "AGENT"
	{
             if (strcmp (Pass, "AGENT01")==0) //Forgot to add ')' after "AGENT01"
		{
			return true;
		}
	}
return false;
}

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

{
	char(User)[100];
	char(Pass)[100];
	bool LoginOk;
	LoginOk= login(User, Pass); // small 'l' in "login"
	if (LoginOk== true ) // missed '(' Before "LoginOk".
	{
		cout<<"Acces granted for "
			<<User<<"."<<endl;
	}
	else
	{
		cout<<"Acess Denied..."<<endl;
	}
	Sleep(3000);

	return 0;

}
Topic archived. No new replies allowed.