Quick problem with password program

I am having one little problem with my password program. At the end it tells you how many valid and invalid passwords you wrote. For some reason the invalid password is not giving the correct number and I don't know why.

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <iomanip>

using namespace std;

int isDigit	(char);				
int isUpper (char);
int isLower (char);

int main()
{

char ch;						
int valid;
int invalid;

cout << "Enter password, ! at the beginning of the line to end" << endl;			
cin.get(ch);

while (ch!='!')		
{

bool digit=false;					
bool upper=false;
bool lower=false;
int i=0;

while(ch!= '\n')					
{
if(isDigit(ch)==true)				
{
digit=true;
cout<<ch;
}

else if(isUpper(ch)==true)			
{
upper=true;
cout<<ch;
}

else if(isLower(ch)==true)			
{
lower=true;
cout<<ch;
}

i++;

cin.get(ch);
}

if(digit==false)
{
cout << endl << "invalid password, missing digit" << endl;		
}

if(upper==false)
{
cout << endl << "invalid password, missing uppercase letter" << endl;		
}

if(lower==false)
{
cout << endl << "invalid password, missing lowercase letter" << endl;		
}

if (i<6)
{
cout << endl << "invalid password, too few characters" << endl;			
}

if(digit==true && upper==true && lower==true && i>=6)
{
cout << endl << "valid password" << endl;			
valid++;
}

else
{
invalid++;
}

cout << endl << "Enter password, ! at the beginning of the line to end" << endl;		
cin.get(ch);
}

invalid--;
cout << endl << "Number of valid passwords:		" <<valid;				
cout << endl << "Number of invalid passwords:	" <<invalid;
	
return 0;	
}





int isDigit (char ch)
{

bool booldigit;							

if(ch>= '0' && ch <= '9')
{
booldigit=true;
}

else
{
booldigit=false;
}

return booldigit;
}






int isUpper (char ch)				
{

bool boolUpper;

if(ch>= 'A' && ch<= 'Z')
{
boolUpper=true;
}

else
{
boolUpper=false;
}
return boolUpper;
}






int isLower(char ch)					
{
bool boolLower;

if(ch>= 'a' && ch<= 'z')
{
	
boolLower=true;
}

else
{
boolLower=false;
}

return boolLower;
}



Last edited on
Thank you in advance.

Your increasing the invalid variable on line 81 without first initialising it, the same with the valid variable in other parts of your program.

Last edited on
Topic archived. No new replies allowed.