OK, I'm going to proceed to list off tons of tips, improvements, errors, bad practice, etc... I hope you don't mind, and if you do just skip this post!
1. If you include
using namespace std;
, then you don't need to put
std::
in front of things from the standard namespace. Likewise, if you use
std::
then you don't need
using namespace std;
2. This:
1 2 3 4 5 6 7
|
char play, PLAY, Play;
char ans;
char user[100];
int iD;
char CorrectUser[100];
int iD2;
std::string Ans; std::string Ans2; std::string Ans3; std::string Ans4; std::string Ans5;
|
Should be something more like:
1 2 3
|
char play, Play, PLAY, ans, user[100], CorrectUser[100];
int iD, iD2;
string Ans, Ans2, Ans3, Ans4, Ans5;
|
Meaning you can declare multiple variables of the same type, on the same line, delimited by commas.
3.
cout << "ChAoS ReIgN" << " V0.99" << " THE ANSW7R LIES W7THIN" << "\n";
doesn't need to be split into multiple strings, i.e. you can do this instead:
cout << "ChAoS ReIgN V0.99 THE ANSW7R LIES W7THIN\n";
(BTW, you can use \t to feed Tab characters to cout (meaning display a tab on screen))
4.
gets(user);
and
cin >> user;
are interchangeable. But in the interests of good practice, you should only use one or the other, not both. I would suggest you stick to cin, unless you're specifically writing a C program, not C++. gets, fgets, printf, etc, are all from C, not C++
5. You don't have to use cout multiple times for something like:
1 2 3 4
|
cout << "Nothing is as it seems,\n";
cout << "Believe no one, Trust no one.\n";
cout << "What is 'Life'?\n";
cout << "The answer lies Within the Game....\n";
|
You can do this instead:
1 2 3 4
|
cout << "Nothing is as it seems,\n"
<< "Believe no one, Trust no one.\n"
<< "What is 'Life'?\n"
<< "The answer lies Within the Game....\n";
|
Note that I omitted the ending semicolons except for the very last one. To the compiler they are essentially all on the same line, it doesn't care about newlines, only semicolons.
6. Instead of using
system("PAUSE");
you should use something internal, like getch(). Look here:
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
cout << "Press any key to exit..." << endl;
getch();
return 0;
}
|
The main problem with making a system() call is that its a big resource hog, the system has to put the program on hold, invoke shell (DOS in this case), then DOS has to find the PAUSE command, then PAUSE creates a process and waits for input (with PAUSE's implementation of that, which is horrid compared to cin), not to mention it's just plain 'ol Bad Practice to outsource your tasks to external programs unless you absolutely have to. C++ has all you need to pause the program (as well as many other things that can be done with windows commands). I've seen c/c++ source that has so many system() calls that it might as well have been a batch file (and that probably would have been more efficient and much less code, if you wanna call it code).
Anyway if you wanna know more about pros and cons of system() then hit up Google.
7. As was said before, you shouldn't use goto's, but use functions and control structures instead.
And finally, here is a modified version of your code (I probably did a few more things that I haven't explained, but I hope you can figure it out yourself, then it's just a matter of working it to your needs (kinda like working clay, or putty)). But one thing that's pretty notable; I got rid of a bunch of your variables, because you really don't need them, you can re-write to the same variables multiple times (that's why they're called variables).
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
|
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
string user, ans;
int main() {
cout << "\nChAoS ReIgN V0.99 THE ansW7R LIES W7THIN\n\n";
while (ans != "y" && ans != "yes" && ans != "g" && ans != "game") {
cout << "Username: ";
cin >> user;
cout << "Your username is " << user << ". Is this correct? ";
cin >> ans;
}
if (ans == "y" || ans == "yes") {
cout << "\nYour Serial number is " << rand() << "\n\n";
cout << "Press any key to exit...";
}
if (ans == "g" || ans == "game") {
cout << "Nothing is as it seems,\n"
<< "Believe no one, Trust no one.\n"
<< "What is 'Life'?\n"
<< "The answer lies Within the Game....\n";
while (ans != "play" && ans != "PLAY" && ans != "Play") {
cout << "\nBefore sarcasm, man made due with OPPOSITES...\n"
<< "Sarcasm has become increasingly popular due to figures in society, \n"
<< "The most recent notability being Hugh Laurie. \n"
<< "His WORK being not so much Inspirational as Entertaining. \n"
<< "Yet he still manages to captivate and hold. A True Ambassador for Sarcasm.\n"
<< "answer: ";
cin >> ans;
}
while (ans != "no" && ans != "NO" && ans != "No") {
cout << "\nLife, A constant Revolution Through Time.\n"
<< "From dusk till dawn, The light comes out only to hide again.\n"
<< "'For the night is long, wont you come out and play?' \n"
<< "The foolish will walk the alleys and face the consequences.\n"
<< "answer: ";
cin >> ans;
}
while (ans != "test") { // This has to be a single word, no spaces, and I don't know why...
cout << "\n106BC-43BC.\n"
<< "In times of war, The law falls silent.\n"
<< "Lots said is mis-understood, So was Cicero.\n"
<< "Inter arma enim silent leges.\n"
<< "Sometimes you musn't look past the actual words.\n";
cin >> ans;
}
}
cout << "\nPress any key to exit...";
getch(); // Pause program; wait for any key;
return 0;
}
|
I can't get around that problem with the last conditional.... It won't accept any string with spaces in it, and I can't figure out why.