Password!!

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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
class Account
{
private:
	int overdraft ;
	float balance ;
	char *name, password[9] ;
public:
	Account(char *N , float bal , int overdrft) ;
	Account() ;
	void Display() ;
	void Deposit() ;
	bool Withdraw() ;
	bool To() ;
	void Print() ;
	void changepassword() ;
} ;

char menu() ;	
bool checkpassword() ;

int main ()
{
	bool option = false,check = false ;
	float balance = 0;
	char *name , temp[80] ;
	cout << "Please key in your name : " ;
	cin.getline(temp,80,'\n') ;
	name = new char(strlen(temp)+1) ;
	strcpy(name,temp) ;
	while(check == checkpassword()) 
	{
		if (check == checkpassword() ) 
		{
			cout << "Please key in the balance : " ;
			cin >> balance ;
			Account Acc	(name,balance,2000) ;
			system("pause") ;
			system("cls") ;
	
			while (!option)
			{		
				char choice = menu() ;
				system("cls") ;
				switch (choice)
				{
					case '1':
					case 'D':
						Acc.Display() ;
						break ;
					case '2':
					case 'E':
						Acc.Deposit() ;
						break ;
					case '3':
					case 'W':
						Acc.Withdraw() ;
						break ; 
					case '4' :
					case 'T':
						Acc.To() ;
						break ;
					case '5' :
					case 'P' :
						Acc.Print() ;
						break ;
					case '6':
					case 'C':
						Acc.changepassword() ;
						break ;
					case '7' :
					case 'Q' :
						exit(1) ;

				}

			}	
		}	
	}
	system("pause") ;
	return 0 ;
}




Account :: Account(char *N , float bal , int overdrft) 
{
	name = N ;
	balance = bal ;
	overdraft = overdrft ;
}

Account :: Account() 
{
	name = new char[2] ;
	name = " " ;
	balance = 0 ; 
	overdraft = 500 ;
	strcpy(password,"password") ;
}


void Account :: Display() 
{

	system("cls") ;
	cout <<"Name : "
		 <<name 
		 <<"\nBalance : "
		 <<balance 
		 <<"\nOverdraft : "
		 <<overdraft 
		 <<endl ;
	cout << password ;
	system("pause") ;
	system("cls") ;
}

void Account ::Deposit()
{
	float Deposit ;
	system("cls") ;
	cout << "Please key in the amount of money u want to deposit : "  ;
	cin >> Deposit ;
	balance = Deposit + balance ;
	system("pause") ;
	system("cls") ;
}

char menu() 
{
	char choice ;
	cout <<"************************************\n"
		 <<" 1) [D]isplay account\n"
		 <<" 2) D[E]posit\n"
		 <<" 3) [W]ithdraw\n"
		 <<" 4) [T]ransfer \n "
		 <<"5) [P]rint balance \n "
		 <<"6) [C]hange password\n "
		 <<"7) [Q]uit\n "
		 <<"************************************\n"
		 <<"Please enter your choice : " ;
	cin >> choice ; 
	cin.ignore(30,'\n') ;
	choice = toupper(choice) ;
	return choice ; 
}

bool Account::Withdraw () 
{
	float amount ;
	cout <<"Please key in the amount of money you want to withdraw: " ;
	cin >> amount ;
	if ((balance + overdraft)<amount)
	{
		cout << "Please try again -- your balance + overdraft do not have sufficient amount of money \n" ;
		system("pause") ;
		system("cls") ;
		return false ;
	}
	else
	{
		cout <<"Transfer done!! :)" ;
		balance = balance - amount  ;
		system("pause") ;
		system("cls") ;
		return true ;

	}
}

bool Account::To()
{
	char *account,temp[80] ;
	float amount ;
	cout << "Please key in the account name you want to transfer to : " ;
	cin.getline(temp,80,'\n') ;
	account = new char (strlen(temp)+1) ;
	strcpy(account,temp);
	cout << "The amount of money: " ;
	cin >> amount ;
	if ((balance + overdraft)<amount)
	{
		cout << "Please try again -- your balance + overdraft do not have sufficient amount of money " ;
		system("pause") ;
		system("cls") ;
		return false ;
	}
	else
	{
		balance = balance - amount  ;
		system("pause") ;
		system("cls") ;
		return true ;

	}


}

bool checkpassword() 
{
	char pass[9] ;
	cout << "Please key in the password : " ;
	cin.getline(pass,9,'\n') ;
	if (strcmp(pass,"password") == 0)
		return false ;
	else 
	{
		cout <<"Invalid password\n" ;
		system("pause") ;
		system("cls") ;
		return true ;
	}

}

void Account :: Print() 
{
	cout <<"Balance : "
		 <<balance 
		 <<endl ;
	system("pause") ;
	system("cls") ;
}

void Account ::changepassword()
{
	char pass[9],temp[9] ;
	int count = 0 ;
	cout <<"Please key in the password : " ;
	cin.getline(pass,9,'\n') ;
	if(strcmp(password,pass) != 0)
	{
		do
		{
			cout <<"\n Invalid Password \n" ;
			cout <<"Please key in the password again : " ;
			cin.getline(pass,9,'\n') ;
			count ++ ;
		}while(count == 2) ;
		if (count == 2)
		{
			cout <<"Password Invalid.... !! Password expired" ;
			system("pause") ;
			exit(1) ;
		}
	}
	else
	{
		do
		{
			cout <<"Please key in new password : " ;
			cin.getline(pass,9,'\n') ;
			cout <<"Please key in the new password again : " ;
			cin.getline(temp,9,'\n') ;
			if(strcmp(temp,pass) != 0)
			{
				cout <<"Invalid password! Please try again.\n  " ;
				system("pause") ;
				system("cls") ;
			}
		}while(strcmp(temp,pass) == 0) ;

	}
	strcmp(password,pass) ;
}


I have problem implementing the option 6; can anyone help me by spotting my mistakes?






Last edited on
http://cplusplus.com/forum/articles/11153/

line 241: }while(count == 2) ;

probably not what you want, as it will never be true
Last edited on
Well there is more mistake besides that lols... I have figured out those problems.
What are the errors you need help with?
Topic archived. No new replies allowed.