C-Strings vs C++ Strings:
You are using C++ yet you still use C-strings? Why is that? You might as well use C if you aren't going to use what C++ provides you with. Trust me, it will make your life a lot easier.
http://www.cprogramming.com/tutorial/string.html
Goto Statements:
They do more harm then good, really. You could easily replace them with some type of loop.
1 2 3 4 5
|
const char* pass = "derp";
char passInput[50];
while(strcmp(passInput, pass) != 0) {
std::cin >> passInput;
}
|
Doesn't that look a lot neater than this..
1 2 3 4 5 6
|
:backUpAgain
const char* pass = "derp";
char passInput[50];
std::cin >> passInput;
if(strcmp(pass, passInput) != 0)
goto backUpAgain;
|
Constant Variables:
You should really use the 'const' keyword if your program isn't going to modify the variable.
Take the 'user' variable for example, you only compare that variable with the data entered by the user, so the contents of the variable will never be changed.
1 2
|
const char USER[]="Cyberspace";
const char PASS[]="asdfjkl";
|
Lack of Indention:
This is really just my personal opinion, but I'll say it anyway. You should really indent your code. And I know, you indented some of it, but not all of it. I find it hard to read without indenting it properly.
Using Whole Namespace:
This is another personal opinion of mine, so you don't _have_ to really read this.
Why don't you just use the prefix 'std'? The main problem with this is name conflicts between two namespaces. Now I know, this doesn't apply to this application because you aren't using two namespaces. Using the prefix is just a good habit to pick up on.
1 2
|
using namespace std;
cout << "hello";
|
Five more characters isn't much.
Summary:
It really boils down to the
goto statements/labels,
constant variables and doing things the
'C++ way'.
- Try to break the habit of using goto statments and labels.
- Start using strings instead of character arrays.
- If the program isn't going to alter it then declare it as a constant.