bug

Pages: 12
It's almost perfect but I noticed that there is one bug. Whenever I choose to not sign up, type random username. It should say invalid username. Please try again. It thinks random username is correct. And I will use #include <ctime> later.

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
#include <iostream>
#include <string>
#include <array>
#include <stdio.h>
#include <ctime>
using namespace std;


int beta[] = { 300, 200, 50, 20, 15 };
int z, y = 0, yes, no;
int main()
{
	string a, b, c, d, e, g, h, i, result, a1, bz, cz;
	int f, answer;
	a1 = "Steel";
 	g = "Bruce Lee";
	i = "Programmer";
	h = "Steel2";
 	yes = 1;
	no = 2;
	do
	{
		std::cout << "Do you need to sign up? Please choose numbers. 1 = yes 2 = no" << endl;
		std::cin >> no;
		if (no == 2)
		{
			{
				std::cout << " " << endl;
				std::cout << "Ok, you may skip this since you have the account!" << endl;
				std::cout << " " << endl;
				goto Username2;
			}
		}
		else
		{
			std::cin.ignore();
			std::cout << " " << endl;
			std::cout << "Welcome, new user!" << endl;
			std::cout << " " << endl;
			std::cout << "What will your new username be?" << endl;
			std::getline(std::cin, bz);
			std::cout << " " << endl;
			std::cout << "What will your new password be?" << endl;
			std::getline(std::cin, cz);
		}
	} 
while (yes != 1);
	do {
		Username2:
		Username:
		std::cin.get();
		std::cout << "Username:" << endl;
		std::getline(std::cin, h);
		if (h != "Steel2", a1 != "Steel")
		{
			{
				std::cout << "Invalid username. Try again." << endl;
				std::cout << " " << endl;
				goto Username;
			
		}
		}
		std::cout << " " << endl;
		std::cout << "Password:" << endl;
		std::getline(std::cin, g);
		if (g != "Superman", i != "Programmer")
		{
			std::cout << "Invalid password. Try again." << endl;
			std::cout << " " << endl;
		}
		else
		{
			std::cout << " " << endl;
			std::cout << "Access Granted..." << endl;
			std::cout << " " << endl;
			std::cout << "Hello \b " << h << "!" << endl;
			std::cout << "What is your first name?" << endl;
			std::getline(std::cin, a);
			std::cout << "What is your middle name?" << endl;
			std::getline(std::cin, b);
			std::cout << "What is your last name?" << endl;
			std::getline(std::cin, c);
			std::cout << "Where are you from?" << endl;
			std::getline(std::cin, d);
			std::cout << "Where are you working?" << endl;
			std::getline(std::cin, e);
			std::cout << "How old are you?" << endl;
			std::cin >> f;
			std::cout << "My full name is \b " << a << " \b " << b << " \b " << c << "." << endl;
			std::cout << "I am from \b " << d << "." << endl;
			std::cout << "My work is in \b " << e << "." << endl;
			std::cout << "I am \b " << f << " years old." << endl;
			for (z = 0; z < 5; ++z)
			{
				y += beta[z];
			}
			std::cout << "Final array result is: \b " << y << endl;
			std::cin.ignore();
			std::cout << "How old am I?" << endl;
			std::cin >> answer;
			if (answer < 32)
			{
				std::cout << "Wrong! I wish I can go back to that age. :)" << endl;
			}
			else if (answer > 32)
			{
				std::cout << "Wrong! Do I look old to you?!" << endl;
			}
			else
			{
				std::cout << "Whoa! That's unbelievable! You got it!" << endl;
			}
			std::cin.get();
			std::cout << "Press any key..." << endl;
			
		}
	} while (g != "Superman", i != "Programmer");
	std::cin.ignore();
	return 0;
}
Last edited on
if (h != "Steel2", a1 != "Steel")
Is absolute equivalent to if (a1 != "Steel") As a1 never changes, that condition is always true. Read on logical operators, it looks like you would want to use them
http://www.learncpp.com/cpp-tutorial/36-logical-operators/
It shouldn't approve if you put different words or letters for username. I am going to read logical operators.
It's almost solved. I still have problems with one thing. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

using namespace std;

Int main()
{

string a;

std::cout << "What will your username be?" << endl;
std::getline(std::cin, a);

do
{
Username:
std::cout << "What is your username?" << endl;
std::getline(std::cin, a)
if (a != a) // I have no ideas about how to add a from std::cin, a. I only know it's possible to do that like this. std::cout << "Your new username is \b " << a << endl; That can come from std::cin, a.
{
std::cout << " " << endl;
std::cout << "Invalid username. Please try again." << endl;
goto Username;
}
Last edited on
if (a != a) // I have no ideas about how to add a from std::cin, a Elaborate what you want. Do you want to check if enterad name is not same as previous?
Any words from a should be approved. Like after you sign up. And then you log in. It should recognize the word from sign up.
@DCisthebest

I think you have put in a good effort for your code, but there are some improvements to be made.

First up, avoid using goto, use loops instead. I am not saying it should be banned, there are situations where expert might use it, but beginners should avoid it .

Also avoid global variables - they can get messy quickly and cause subtle problems. Try to keep the scope of variables as local as possible.

Next, try to use functions. Compound statements (code between braces) as found in loops, if and switch or case are good candidates for functions. Use of functions makes the code easier to understand because it provides a little bit of abstraction. If there was a function named GetUserData, and it works - then this becomes easy to understand:

1
2
3
if (LoginSuccess) {
    GetUserData();
}


The details of GetUserData appear after main(), so the reader of the code in main can think about things at a higher level, rather than be bogged down in detail.

There is a bit of a rule that functions should be no longer 40LOC - and that includes main(). Some go for even less. The point is that functions should do 1 well defined thing.

If you name your functions and variables well, then the code becomes self documenting and should almost read like sentences and paragraphs. Or if you like, it tells the story of what the code does. Names like a, b , c ,d aren't good examples of variable names in this context. Consider FirstName , MiddleName etc. Someone who knows very little about the subject of your code should be able to read the code and not be confused.

Avoid using namespace std; - you already have std:: for most of the code - just need to add it for string as well. There is lots written on the net as to why this is a good idea.

From a style POV it is good to declare 1 variable per LOC. If it is not an STL thing (like std::string say) then you should initialise the variable at the same time as declaration. Comments can be put in to describe things like expected range of valid values.

With variables that are going to have yes / no values consider using a bool type. Consider using SignUpOption rather than yes / no.

Try to avoid having magic numbers like 32 in your code. Make them const variables instead, then use the variable name from then on:

1
2
3
4
5
6
const unsigned short AgeLimit = 32;
constexpr unsigned short AgeLimit = 32; // in c++11 we can use constexpr

if (answer < AgeLimit) {
   // Do stuff
}


With your do loop on line 48, there doesn't seem to be a way for the user to exit early.

Duoas is spending a lot of effort & time writing an excellent FAQ for beginners, there is a Topic about it at the moment. Here is an excellent paper on variable naming that is linked in Duoas' article- well worth reading:

http://www.objectmentor.com/resources/articles/Naming.pdf


Any way good luck with your coding - I hope that I have helped a bit :+)
I tried GetUserData(); It doesn't work successfully. If I remove using namespace std;, I receive 95 errors.

Note:

I chose this like this before I start typing C++

New Project -> Visual C++ -> Win32 Console Application
Add new item -> C++ File (.cpp)
Last edited on
Hi,

I tried GetUserData();


So what does the code for that look like? Maybe you should post all your code so far, so I (& others) can see how you are doing. If you are going to use functions, declare them before main(), and define them after main()

If I remove using namespace std;, I receive 95 errors.


TheIdeasMan wrote:
Avoid using namespace std; - you already have std:: for most of the code - just need to add it for string as well. There is lots written on the net as to why this is a good idea.


Did you read up about this on Google?

Hope all goes well :+)
I changed a little bit expect removing using namespace std; and GetUserData();

I read some of them from google.

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
#include <iostream>
#include <string>
#include <array>
#include <stdio.h>
#include <ctime>
using namespace std;


int beta[] = { 300, 200, 50, 20, 15 };
int z, y = 0, yes, no;
int main()
{
	string a, b, c, d, e, g, h, i, result, bz, cz;
	int f, answer;
	g = "Bruce Lee";
	h = "Steel";
	yes = 1;
	no = 2;
	const unsigned short Agelimit = 32;
		std::cout << "Do you need to sign up? Please choose numbers. 1 = yes 2 = no" << endl;
		std::cin >> no;
		if (no == 2)
		{
			{
				std::cout << " " << endl;
				std::cout << "Ok, you may skip this since you have the account!" << endl;
				std::cout << " " << endl;
				goto Username2;
			}
		}
		else
		{
			std::cin.ignore();
			std::cout << " " << endl;
			std::cout << "Welcome, new user!" << endl;
			std::cout << " " << endl;
			std::cout << "What will your new username be?" << endl;
			std::getline(std::cin, bz);
			std::cout << " " << endl;
			std::cout << "What will your new password be?" << endl;
			std::getline(std::cin, cz);
		}
	do {
		Username2:
		Username:
		std::cin.get();
		std::cout << "Username:" << endl;
		std::getline(std::cin, h);
		if (h != "Steel")
		{
			{
				std::cout << "Invalid username. Try again." << endl;
				std::cout << " " << endl;
				goto Username;
			}
		}
		std::cout << " " << endl;
		std::cout << "Password:" << endl;
		std::getline(std::cin, g);
		if (g != "Superman")
		{
			std::cout << "Invalid password. Try again." << endl;
			std::cout << " " << endl;
		}
		else
		{
			std::cout << " " << endl;
			std::cout << "Access Granted..." << endl;
			std::cout << " " << endl;
			std::cout << "Hello \b " << h << "!" << endl;
			std::cout << "What is your first name?" << endl;
			std::getline(std::cin, a);
			std::cout << "What is your middle name?" << endl;
			std::getline(std::cin, b);
			std::cout << "What is your last name?" << endl;
			std::getline(std::cin, c);
			std::cout << "Where are you from?" << endl;
			std::getline(std::cin, d);
			std::cout << "Where are you working?" << endl;
			std::getline(std::cin, e);
			std::cout << "How old are you?" << endl;
			std::cin >> f;
			std::cout << "My full name is \b " << a << " \b " << b << " \b " << c << "." << endl;
			std::cout << "I am from \b " << d << "." << endl;
			std::cout << "My work is in \b " << e << "." << endl;
			std::cout << "I am \b " << f << " years old." << endl;
			for (z = 0; z < 5; ++z)
			{
				y += beta[z];
			}
			std::cout << "Final array result is: \b " << y << endl;
			std::cin.ignore();
			std::cout << "How old am I?" << endl;
			std::cin >> answer;
			if (answer < Agelimit)
			{
				std::cout << "Wrong! I wish I can go back to that age. :)" << endl;
			}
			else if (answer > Agelimit)
			{
				std::cout << "Wrong! Do I look old to you?!" << endl;
			}
			else
			{
				std::cout << "Whoa! That's unbelievable! You got it!" << endl;
			}
			std::cout << " " << endl;
			std::cin.get();
			std::cout << "Press any key..." << endl;
			
		}
	} while (g != "Superman");
	std::cin.ignore();
	return 0;
}
Last edited on
Hi,
So what did you change? It looks like your original code.

I am at work so only a brief reply 😃
Cheers
I removed do { } while (yes != 1); and added const unsigned short Agelimit = "32" and if (answer > Agelimit), and else if (answer < Agelimit) as you suggested.
hi,

With the namespace std thing, start out by removing line 6, and changing string to std::string on line 13. This should cut down on a lot of the errors. Better, try to understand what is happening - did you read up on what a namespace is for?

Then, it would be good if you could change the names of your variables, as I mentioned earlier. In your IDE somewhere there should be an option to refactor code (change variable name). This should go through and change all of them automatically throughout the code. For example change a to NameFirst

Then get rid of your yes & no variables, add a bool SignUp; variable instead. A bool is a variable that is either true or false. You have 2 lots of yes & no variables, one pair is global, the other pair is in main - so get rid of all 4 of them. Make sure you change the rest of your code that uses those variables to make sure it works with your new variable name.

See how you go with that :+)

I removed using namespace std and put std::string on line 13. I put using std::getline; and the others. It seems to be ok.

I am not sure about where to place bool SignUp; And yes I was reading the info about namespace. That is for code declarations.

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
#include <iostream>
#include <string>
#include <array>
#include <stdio.h>
#include <time.h>



int beta[] = { 300, 200, 50, 20, 15 };
int z, y = 0, yes, no;
int main()
{
	using std::cout;
	using std::cin;
	using std::endl;
	using std::getline;
	std::string NameFirst, NameMiddle, NameLast, location, joblocation, passcode, memberuser, result, bz, cz;
	int f, answer;
	passcode = "Bruce Lee";
	memberuser = "Steel";
	yes = 1;
	no = 2;
	const unsigned short Agelimit = 32;
	cout << " " << endl;
		cout << "Do you need to sign up? Please choose numbers. 1 = yes 2 = no" << endl;
		cin >> no;
		if (no == 2)
		{
			{
				cout << " " << endl;
				cout << "Ok, you may skip this since you have the account!" << endl;
				cout << " " << endl;
				goto Username2;
			}
		}
		else
		{
			cin.ignore();
			cout << " " << endl;
			cout << "Welcome, new user!" << endl;
			cout << " " << endl;
			cout << "What will your new username be?" << endl;
			getline(cin, bz);
			cout << " " << endl;
			cout << "What will your new password be?" << endl;
			getline(cin, cz);
		}
	do {
		Username2:
		Username:
		cin.get();
		cout << "Username:" << endl;
		getline(cin, memberuser);
		if (memberuser != "Steel")
		{
			{
				cout << "Invalid username. Try again." << endl;
				cout << " " << endl;
				goto Username;
			}
		}
		cout << " " << endl;
		cout << "Password:" << endl;
		getline(cin, passcode);
		if (passcode != "Bruce Lee")
		{
			cout << "Invalid password. Try again." << endl;
			cout << " " << endl;
		}
		else
		{
			cout << " " << endl;
			cout << "Access Granted..." << endl;
			cout << " " << endl;
			cout << "Hello \b " << memberuser << "!" << endl;
			cout << "What is your first name?" << endl;
			getline(cin, NameFirst);
			cout << "What is your middle name?" << endl;
			getline(cin, NameMiddle);
			cout << "What is your last name?" << endl;
			getline(cin, NameLast);
			cout << "Where are you from?" << endl;
			getline(cin, location);
			cout << "Where are you working?" << endl;
			getline(cin, joblocation);
			cout << "How old are you?" << endl;
			cin >> f;
			cout << "My full name is \b " << NameFirst << " \b " << NameMiddle << " \b " << NameLast << "." << endl;
			cout << "I am from \b " << location << "." << endl;
			cout << "My work is in \b " << joblocation << "." << endl;
			cout << "I am \b " << f << " years old." << endl;
			for (z = 0; z < 5; ++z)
			{
				y += beta[z];
			}
			cout << "Final array result is: \b " << y << endl;
			cin.ignore();
			cout << "How old am I?" << endl;
			cin >> answer;
			if (answer < Agelimit)
			{
				cout << "Wrong! I wish I can go back to that age. :)" << endl;
			}
			else if (answer > Agelimit)
			{
				cout << "Wrong! Do I look old to you?!" << endl;
			}
			else
			{
				cout << "Whoa! That's unbelievable! You got it!" << endl;
			}
			cout << " " << endl;
			cin.get();
			cout << "Press any key..." << endl;
			
		}
	} while (passcode != "Bruce Lee");
	cin.ignore();
	return 0;
}
Last edited on
Alright - Good Work so far :+)

I am not sure about where to place bool SignUp;


In C++ variable declarations can be placed anywhere before they are needed, so you could put it before line 25.

And yes I was reading the info about namespace. That is for code declarations.


But the main idea of it is to avoid name clashes, having using namespace std; defeats that purpose. It is also a good idea to put your own code in your own namespaces. That way, if I write code in my own namespaces, I can have a NameFirst variable without it being confused with your one. This is perhaps not important at this stage, but at least the idea has been put forward - you might be able to make use of it in the future.

Btw, there are still some variable names you could change (f , z, y, bz, cz ). Also some of the others could be even clearer: result of what? ; memberuser could just be NameLogin ; answer could be AgeGuess

With the using std::cout; etc, - I used to do that, but in the end it is better to put std:: before each and every occurrence of a std thing. Also, if you look at code by some of the experts on this site, you can see they always do that. In your original code you had std::cout etc everywhere, you were only missing the std::string ones.

Now about functions - you said you had trouble getting a function to work, but haven't shown the code you had. I wonder have you learnt about functions yet? Are you aware of the reference material on this site? If not have a look at the top left of the page - there is a comprehensive tutorial, and reference material about all the functions algorithms & containers in the STL. You could read up about functions & std::string for example.

Good luck - keep learning :+)
Is bool SignUp; in the right place?

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
#include <iostream>
#include <string>
#include <array>
#include <stdio.h>
#include <time.h>



int beta[] = { 300, 200, 50, 20, 15 };
int z, y = 0, yes, no;
int main()
{
	using std::cout;
	using std::cin;
	using std::endl;
	using std::getline;
	using std::string;
	string NameFirst, NameMiddle, NameLast, location, joblocation, passcode, UNameLogin, SignUpUsers, SignUpPass;
	int Age, AgeGuess;
	passcode = "Bruce Lee";
	UNameLogin = "Steel";
	yes = 1;
	no = 2;
	const unsigned short Agelimit = 32;
	cout << " " << endl;
        bool SignUp;
		cout << "Do you need to sign up? Please choose numbers. 1 = yes 2 = no" << endl;
		cin >> no;
		if (no == 2)
		{
			{
				cout << " " << endl;
				cout << "Ok, you may skip this since you have the account!" << endl;
				cout << " " << endl;
				SignUp = false;
				goto Username2;
			}
		}
		else
		{
			cin.ignore();
			cout << " " << endl;
			cout << "Welcome, new user!" << endl;
			cout << " " << endl;
			cout << "What will your new username be?" << endl;
			getline(cin, SignUpUsers);
			cout << " " << endl;
			cout << "What will your new password be?" << endl;
			getline(cin, SignUpPass);
			SignUp = true;
		}
	do {
		Username2:
		Username:
		cin.get();
		cout << "Username:" << endl;
		getline(cin, UNameLogin);
		if (UNameLogin != "Steel")
		{
			{
				cout << "Invalid username. Try again." << endl;
				cout << " " << endl;
				goto Username;
			}
		}
		cout << " " << endl;
		cout << "Password:" << endl;
		getline(cin, passcode);
		if (passcode != "Bruce Lee")
		{
			cout << "Invalid password. Try again." << endl;
			cout << " " << endl;
		}
		else
		{
			cout << " " << endl;
			cout << "Access Granted..." << endl;
			cout << " " << endl;
			cout << "Hello \b " << UNameLogin << "!" << endl;
			cout << "What is your first name?" << endl;
			getline(cin, NameFirst);
			cout << "What is your middle name?" << endl;
			getline(cin, NameMiddle);
			cout << "What is your last name?" << endl;
			getline(cin, NameLast);
			cout << "Where are you from?" << endl;
			getline(cin, location);
			cout << "Where are you working?" << endl;
			getline(cin, joblocation);
			cout << "How old are you?" << endl;
			cin >> Age;
			cout << "My full name is \b " << NameFirst << " \b " << NameMiddle << " \b " << NameLast << "." << endl;
			cout << "I am from \b " << location << "." << endl;
			cout << "My work is in \b " << joblocation << "." << endl;
			cout << "I am \b " << Age << " years old." << endl;
			for (z = 0; z < 5; ++z)
			{
				y += beta[z];
			}
			cout << "Final array result is: \b " << y << endl;
			cin.ignore();
			cout << "How old am I?" << endl;
			cin >> AgeGuess;
			if (AgeGuess < Agelimit)
			{
				cout << "Wrong! I wish I can go back to that age. :)" << endl;
			}
			else if (AgeGuess > Agelimit)
			{
				cout << "Wrong! Do I look old to you?!" << endl;
			}
			else
			{
				cout << "Whoa! That's unbelievable! You got it!" << endl;
			}
			cout << " " << endl;
			cin.get();
			cout << "Press any key..." << endl;
			
		}
	} while (passcode != "Bruce Lee");
	cin.ignore();
	return 0;
}
Last edited on
I think I understand what you meant by true and false. I think this code is right. I am thinking about how to add new username into real login after you create the new account.

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
#include <iostream>
#include <string>
#include <array>
#include <stdio.h>
#include <time.h>



int beta[] = { 300, 200, 50, 20, 15 };
int z, y = 0;
int main()
{
	using std::cout;
	using std::cin;
	using std::endl;
	using std::getline;
	using std::string;
	string NameFirst, NameMiddle, NameLast, location, joblocation, passcode, UNameLogin, SignUpUsers, SignUpPass;
	int Age, AgeGuess;
	passcode = "Bruce Lee";
	UNameLogin = "Steel";
	const unsigned short Agelimit = 32;
	bool SignUp;
	cout << " " << endl;
		cout << "Do you need to sign up? Please choose numbers. 1 = To skip or 0 = To create the new account" << endl;
		cin >> SignUp;
		if (SignUp)
		{
			{
				cout << " " << endl;
				cout << "Ok, you may skip this since you have the account!" << endl;
				cout << " " << endl;
				goto Username2;
			}
		}
		else
		{
			cin.ignore();
			cout << " " << endl;
			cout << "Welcome, new user!" << endl;
			cout << " " << endl;
			cout << "What will your new username be?" << endl;
			getline(cin, SignUpUsers);
			cout << " " << endl;
			cout << "What will your new password be?" << endl;
			getline(cin, SignUpPass);
		}
	do {
		Username2:
		Username:
		cin.get();
		cout << "Username:" << endl;
		getline(cin, UNameLogin);
		if (UNameLogin != "Steel")
		{
			{
				cout << "Invalid username. Try again." << endl;
				cout << " " << endl;
				goto Username;
			}
		}
		cout << " " << endl;
		cout << "Password:" << endl;
		getline(cin, passcode);
		if (passcode != "Bruce Lee")
		{
			cout << "Invalid password. Try again." << endl;
			cout << " " << endl;
		}
		else
		{
			cout << " " << endl;
			cout << "Access Granted..." << endl;
			cout << " " << endl;
			cout << "Hello \b " << UNameLogin << "!" << endl;
			cout << "What is your first name?" << endl;
			getline(cin, NameFirst);
			cout << "What is your middle name?" << endl;
			getline(cin, NameMiddle);
			cout << "What is your last name?" << endl;
			getline(cin, NameLast);
			cout << "Where are you from?" << endl;
			getline(cin, location);
			cout << "Where are you working?" << endl;
			getline(cin, joblocation);
			cout << "How old are you?" << endl;
			cin >> Age;
			cout << "My full name is \b " << NameFirst << " \b " << NameMiddle << " \b " << NameLast << "." << endl;
			cout << "I am from \b " << location << "." << endl;
			cout << "My work is in \b " << joblocation << "." << endl;
			cout << "I am \b " << Age << " years old." << endl;
			for (z = 0; z < 5; ++z)
			{
				y += beta[z];
			}
			cout << "Final array result is: \b " << y << endl;
			cin.ignore();
			cout << "How old am I?" << endl;
			cin >> AgeGuess;
			if (AgeGuess < Agelimit)
			{
				cout << "Wrong! I wish I can go back to that age. :)" << endl;
			}
			else if (AgeGuess > Agelimit)
			{
				cout << "Wrong! Do I look old to you?!" << endl;
			}
			else
			{
				cout << "Whoa! That's unbelievable! You got it!" << endl;
			}
			cout << " " << endl;
			cin.get();
			cout << "Press any key..." << endl;
			
		}
	} while (passcode != "Bruce Lee");
	cin.ignore();
	return 0;
}
Last edited on
ok, how are you going with the others things on the list?
don't use goto statements as they are unconditional jump.rather use functions instead of goto statements.

http://www.tutorialspoint.com/cprogramming/c_goto_statement.htm
It's really hard for me to explain this to you, TheIdeasMan. Let me put the example here. It's going to be the same from my code.

1
2
3
4
5
cout << "What will your new username be?" << endl;
			getline(cin, SignUpUsers); //Anyone puts his or her new username for signup.
                        cout << "Username:" << endl;
		getline(cin, UNameLogin); //SignUpUsers should be added to this line too.
		if (UNameLogin != "Steel") //I am not sure if it works like this for SignUpUsers in this line cause he or she puts random word or letter or etc. Like this if (UNameLogin != "Steel" && SignUpUsers) or something like that. 


@appi I am going to remove goto and see how's it going on now.

Pages: 12