Trouble getting program to repeat

I'm having trouble getting this program to repeat again after use. After each password input (whether valid or invalid), I need it to ask if I want to run the program again. Any ideas on why it's not working?

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
#include <iostream>
#include <cstring>

using namespace std;

char again;

int main()
{
	do
	{
		const int size = 1000;

		char password[size];
		int count;
		int error1 = 0;
		int error2 = 0;
		int error3 = 0;

		cout << "-----Password Requirements-----" << endl << "At least..." << endl 
			<< "1 digit" << endl << "1 uppercase letter" << endl << "1 lowercase letter" 
			<< endl << "6 characters total." << endl << endl;

		cout << "Enter your password: ";
		cin.getline(password, size);

		if (strlen(password) < 6)
		{
			cout << "Password Invalid. Must contain at least 6 characters";
		}

		for(count = 0; count < strlen(password); count++)
		{
			if (isupper(password[count]))
			{
				error1++;
			}

			if (islower(password[count]))
			{
				error2++;
			}

			if (isdigit(password[count]))
			{
				error3++;
			}
		}

		if (error1 == 0)
		{
			cout << "Invalid Password. Must include at least 1 uppercase letter." << endl;
		}

		if (error2 == 0)
		{
			cout << "Invalid Password. Must include at least 1 lowercase letter." << endl;  
		}

		if (error3 == 0)
		{
			cout << "Invalid Password. Must include at least 1 digit." << endl;
		}

		else
		{
			cout << "Password Verified." << endl;
		}


		cin.get();

		cout << "Do you want to run this program again? Y/N: ";
		cin >> again;

	} while (again == 'y' || again == 'Y');
	return 0;
}
I am not sure what you up to... cuz there were lots of logic errors, however i tried to fix it as you want <<<<<< it could be done with other easier ways

check this out

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
#include <iostream>
#include <cstring>

using namespace std;

char again;

int main()
{
	do
	{
		const int size = 1000;

		char password[size];
		int count;
		int error1 = 0;
		int error2 = 0;
		int error3 = 0;

		cout << "-----Password Requirements-----" << endl << "At least..." << endl 
			<< "1 digit" << endl << "1 uppercase letter" << endl << "1 lowercase letter" 
			<< endl << "6 characters total." << endl << endl;

		cout << "Enter your password: ";
		cin.getline(password, size);

		if (strlen(password) < 6)
		{
			cout << "Password Invalid. Must contain at least 6 characters";
		}
		
		else if (strlen(password) == 6)
		{
			for(count = 0; count < strlen(password); count++)
			{
				if (isupper(password[count]))
				{
					error1++;
				}

				if (islower(password[count]))
				{
					error2++;
				}

				if (isdigit(password[count]))
				{
					error3++;
				}
			}

			if (error1 == 0)
			{
				cout << "Invalid Password. Must include at least 1 uppercase letter." << endl;
			}

			if (error2 == 0)
			{
				cout << "Invalid Password. Must include at least 1 lowercase letter." << endl;  
			}

			if (error3 == 0)
			{
				cout << "Invalid Password. Must include at least 1 digit." << endl;
			}

			if(error3 != 0 && error2 != 0 && error1 != 0 )
			{
				cout << "Password Verified." << endl;
			}
		}

		cout << "Do you want to run this program again? Y/N: ";
		cin >> again;
		cin.ignore();
	} while (again == 'y' || again == 'Y');
	return 0;
}
Last edited on
Thanks for the help! Assignment directions wanted it done a specific way. Thanks again!
Topic archived. No new replies allowed.