Having trouble with this logic

1
2
3
4
5
6
7
8
9
10
11
12
13
string password;
string input = "";
int pass = 0;
while (true) {
		cout << "Enter your Password: ";
		getline(cin, input);
		cin >> password;
		stringstream myStream(input);
		if (myStream >> pass && password.length() <= 6)
			break;
		cout << "ENTER ONLY NUMBER AND WITH A LIMIT OF 6" << endl;
		cin >> password;
	}



hello please help me with this one I'd like to check if the password given is number or length is only 6 and lower but the problem with this, it always give the output ENTER NUMBER AND WITH A LIMIT OF 6
Last edited on
Add this before line 11:
cout << "input=" << input << "\npassword=" << password << "pass=" << pass << '\n';

I'm sure you'll find that the values aren't what you think they are. Then, before changing the code, look at lines 6-9 and explain, line by line, what you think each line is doing.
Thank you dhayden but sorry because I'm just bad :( that moment it is the last code and none other than that so naturally no response :O :( lol. sorry.
Topic archived. No new replies allowed.