Password

Trying to make where user has to enter 7 characters to make password having trouble with this if statement

if (password2[7])

{
cout << "Please Enter at least 7 characters\n";
goto repeat3;
}




#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>




using namespace std;





char username1;
char username2[6];
int Login;


int User()
{




cout << "Please Enter a User Id\n";
cout << "User Id must be at least 6 characters long\n";
repeat1:
cin >> username2;
if (username2[6] <= username1)
{
cout << "Please ReEnter Id Not enough characters\n";
goto repeat1;
}
else
cout << "Your User Id is "<< username2 << endl;

}





int Pass()
{

cout << "Please Enter your password\n";
cout << "Your password must be at least 7 characters long\n";

repeat3:
repeat2:

string password1;
string password2;

cin >> password1;
cout << "Please ReEnter your password\n";
cin >> password2;

if (password1 != password2)
{
cout << "You have ReEnter your password incorrectly \n";
goto repeat2;
}


if (password2[7])

{
cout << "Please Enter at least 7 characters\n";
goto repeat3;
}



else
cout << "You Now logged on to treasure Island\n";


}

int Welcome()

{
cout << "Welcome to Adam's Quiz Game\n";
cout << "Login Enter 1 " "Create New Account Enter 2 \n" "Press 3 to Quit\n";

cin >> Login;
if (Login == 2)

{
User();
Pass();
}

if (Login ==1)

{
cout << "bye\n";
}

}


int main()

{
Welcome ();

//ofstream dataFile;
//dataFile.open("data.txt", ios::in|ios::binary|ios::ate);
//dataFile << username1;
//dataFile.close();




system("PAUSE");
return 0;
}





from a quick look, it doesn't look as though you need it, at all..

i made a couple of changes, have a look, is this right??

also i think you need to have a look at the username char limit..

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
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

char username1;
char username2[6];
int Login; 

int User()
{
	cout << "Please Enter a User Id\n";
	cout << "User Id must be at least 6 characters long\n";
	repeat1:
	cin >> username2;
	if (username2[6] <= username1)
	{
		cout << "Please ReEnter Id Not enough characters\n";
		goto repeat1;
	}
	else cout << "Your User Id is "<< username2 << endl;
}



int Pass() 
{ 
	repeat2: 

	cout << "Please Enter your password\n";
	cout << "Your password must be at least 7 characters long\n\n>> ";


	string password1;
	string password2;

	cin >> password1;
	cout << "Please ReEnter your password\n";
	cin >> password2;

	if (password1 != password2)
	{
		cout << "You have ReEnter your password incorrectly \n\n";
		goto repeat2;
	}

	else cout << "You Now logged on to treasure Island\n";

}

int Welcome()

{
	cout << "Welcome to Adam's Quiz Game\n";
	cout << "Login Enter 1 " "Create New Account Enter 2 \n" "Press 3 to Quit\n";

	cin >> Login;

	if (Login == 2)
	{
		User();
		Pass();
	}

	if (Login ==1)
	{
		cout << "bye\n";
	}

}


int main()
{
	Welcome ();

	//ofstream dataFile;
	//dataFile.open("data.txt", ios::in|ios::binary|ios::ate);
	//dataFile << username1;
	//dataFile.close();

	system("PAUSE");
	return 0;
}


i didn't test it or anything so tell me how you get on, if it's wrong still ill try have a better look..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

std::string getStringOfMinLength(const std::string& prompt, unsigned minLength)
{
    std::cout << prompt << '\n' << "(min length = " << minLength << ")\n" ;

    std::string str ;
    while ( std::cin >> str && str.length() < minLength )
        std::cout << "Not long enough! (min length = " << minLength << ")\n" ;

    return str; 
}

int main()
{
    std::string userName = getStringOfMinLength("Please enter a user ID", 6) ;
    std::string password = getStringOfMinLength("Please enter a password", 7) ;

    std::cout << "User name: " << userName << "\nPassword: " << password << '\n' ;
}
Topic archived. No new replies allowed.