Access Granted

Im trying to get the program work correctly and its running, but the problem is as soon as i enter the username and hit enter, it doesnt allow me to enter password to be entered but it displays all the process after that.

Hers my code:
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
#include <iostream>
#include <string>
using namespace std;

int main()
{
	char inputUser, inputPass;
	int foundFlag, k;
	int userName [10];
	int passWord [10];
	
	for (k = 0; k <= 2; k++){
		cout <<"Enter the Username: ";
		cin >> userName[k];
		cout <<"Enter the Password: ";
		cin >> passWord[k];}
	cout <<"Input User: ";
	cin >> inputUser;
	foundFlag = false;
	for (k = 1; k <= 2; ++k){
		if (inputUser = userName[k])
			foundFlag = true;
		cout <<"Input Pass: ";
		cin >> inputPass;
		if (inputPass = passWord[k])
			cout <<"Access granted.";
		else
			cout <<"Username and password do not match.";
	}
	if (foundFlag = false)
		cout <<"Username not Found";
	
	system("PAUSE");
	return 0;
}


and this is what im getting as soon i enter the username and hit enter
1
2
3
4
Enter the Username: John
Enter the Password: Enter the Username: Enter the Password: Enter the Username:
Enter the Password: Input User: Input Pass: Access granted.Input Pass: Access gr
anted.Press any key to continue . . .
'username[k]' is an int. This means that it can only contain an integer value... it cannot contain a string.

You are giving it a string. So cin fails and just returns immediately while leaving your string ("John") in the buffer.

Change username and password to be arrays of strings... rather than arrays of ints.
@ Disch thank you for help, i got it now. here's my updated code
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
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string inputUser, inputPass;
	int foundFlag, k;
	string userName [10];
	string passWord [10];
	
	for (k = 1; k <= 2; k++){
		cout <<"Enter the Username: ";
		cin >> userName[k];
		cout <<"Enter the Password: ";
		cin >> passWord[k];}
	cout <<"Input User: ";
	cin >> inputUser;
	foundFlag = false;
	for (k = 1; k <= 2; k++){
		if (inputUser == userName[k])
			foundFlag = true;
		cout <<"Input Pass: ";
		cin >> inputPass;
		if (inputPass == passWord[k])
			cout <<"Access granted.";
		else
			cout <<"Username and password do not match.";
	}
	if (foundFlag = false)
		cout <<"Username not Found";
	
	system("PAUSE");
	return 0;
}
Topic archived. No new replies allowed.