Looking for some advice.

closed account (GvfGNwbp)
Hey guys,
im pretty new to c++ programming and am using visual c++ 2010.
I recently created a little program and the best way to describe it
is by saying its similar to the terminal hacks from the video game fallout.
its a simple program that asks you to select a password from a list, the correct
one shows some text while the incorrest answer displays an error and closes the
program. Im looking for some advice that could help make it simpler, more neat
and to explain any errors i've made to me. Any improvements you think would be good i will happily try them as im new to this and want to soak up as much info as poosible... i will post the code below if anybody wants to try it. 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
#include <iostream>
#include "conio.h"
#include <string>
#include <cstdlib>

using namespace std;

void main(){
	string Key;
	string Password;
	cout << " Terminal Security Manual Overide " << endl;
	cout << endl;
	cout << " Enter Overide Key to Begin " << endl;
	cout << endl;
	cin >> Key;
	cout << endl;
	cout << " Valid Key Detected " << endl;
	cout << endl;
	cout << " Entering Boot Screen" << endl;
	_getch();
	system("cls");
	cout << " Password Required to Continue" << endl;
	cout << endl;
	cout << " $#//£..Paradise<=&DyGJJ-@# " << endl;
	cout << " Computer[=)(.$Contribute%%#$$" << endl;
	cout << " ../.@.!Arrival##/.*&£%%%%" << endl;
	cout << " %#Return@.//%&8#.!Weather.@" << endl;
	cout << endl;
	cout << " Retype Correct Password to Continue " << endl;
	cout << endl;
	cin >> Password;
	if(Password == "Contribute"){
		cout << endl;
		cout << " Correct Password... Confirmed" << endl;
		_getch();
		system("cls");
		cout << endl;
		cout << " Top Secret Missile Launch Codes" << endl;
		cout << endl;
		cout << " Launch Code Alpha : 21700326 " << endl;
		cout << endl;
		cout << " Launch Code Bravo : 61927101 " << endl;
		cout << endl;
		cout << " Launch Code 'X' Primary : 010094205319670 " << endl;
		cout << "               Secondary : 1905 " << endl;
	}
		else if(Password == "Paradise", "Computer", "Return"){
		system("cls");
		cout << endl;
		cout << " Security Clearance Failed " << endl;
		cout << endl;
		cout << endl;
		cout << endl;
		cout << " Please Contact The Administrator" << endl;
	}
	_getch();
}
Last edited on
Please edit your post and use [ code ] [/ code ] tags.

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
#include <iostream>
#include "conio.h"
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
	string Key;
	string Password;

	cout << " Terminal Security Manual Overide\n\n"
		 << " Enter Overide Key to Begin\n\n";

	cin >> Key;

	cout << "\n Valid Key Detected\n\n"
		 << " Entering Boot Screen\n";

	_getch();
	system("cls");

	cout << " Password Required to Continue\n\n"
		 << " $#//£..Paradise<=&DyGJJ-@#\n"
		 << " Computer[=)(.$Contribute%%#$$\n"
		 << " ../.@.!Arrival##/.*&£%%%%\n"
		 << " %#Return@.//%&8#.!Weather.@\n\n";

	cout << " Retype Correct Password to Continue\n\n";

	cin >> Password;

	if(Password == "Contribute")
	{
		cout << "\n Correct Password... Confirmed\n";

		_getch();
		system("cls");

		cout << "\n Top Secret Missile Launch Codes\n"
			 << " Launch Code Alpha : 21700326\n\n"
			 << " Launch Code Bravo : 61927101\n\n"
			 << " Launch Code 'X' Primary : 010094205319670\n"
			 << " Secondary : 1905\n";
	}
	else if(Password == "Paradise" || Password == "Computer" || Password == "Return")
	{
		system("cls");
		cout << "\n Security Clearance Failed\n\n\n\n"
		        << " Please Contact The Administrator\n";
	}
	_getch();

	return 0;
} 


I made some simple changes. Interesting program by the way.
Last edited on
closed account (GvfGNwbp)
Thanks phil will try it with changes now, sorry i did'nt know about the code tags.
The code should now be formated with the tags.
By the way is /n an easier way to skip a line in the program because uptill now i've been using
cout << endl;
Last edited on
For me personally, it depends on what I'm doing.

1
2
3
4
5
6
7
cout << someInteger << endl;
// looks alot nicer than
cout << someInteger << "\n";
// and
cout << "Hello, how are you?\n";
// is a little less work than
cout << "Hello, how are you?" << endl;
I prefer endl. So I'm on the safe side if I want a line break in console on different operating systems (windows "\r\n", linux "\n", mac "\r").
Last edited on
Your password checking is a little flawed. What if I type bananas? You should fix this problem I'm hinting at.

endl comes with more than just a newline, though. Also flushes the buffer, which can be kind of costly.
closed account (GvfGNwbp)
Thanks everybody i appreciate the replies.
Also flushes the buffer, which can be kind of costly.


Care to explain? I'm thirsty for more knowledge.
Basically, \n is just a character. It has an ascii value and all that jazz. std::endl is a stream manipulator, which is a function. As you can already probably imagine, that's going to be more costly.
Basically, \n is just a character. It has an ascii value and all that jazz. std::endl is a stream manipulator, which is a function. As you can already probably imagine, that's going to be more costly.


Good to know, thanks.
Topic archived. No new replies allowed.