need help at password and username looping

can i have a sample? i dont know how to insert words in a program
sorry im just a beginner
:D

You should first read up on <string> http://www.cplusplus.com/reference/string/ and then you will know how to accept user input in the form of words and what tools are available to manipulate and compare the text.
closed account (LzwkoG1T)
For basics, let the user input a password. Presume that you know the password to be " ABC ".
so its a basic if ( password == ABC ), grant access.
so in putting variables it should br like...
int password == abc???
closed account (LzwkoG1T)
No, that was just a rough example.
what you can do , is delcare a string which will be the password, and compare the user input to that string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string password = "password";

	string pwd;
	cin >> pwd;
	if( pwd == password )
		cout << "Correct" << endl;

	cin.get();
	cin.ignore();
	return 0;

}

closed account (LzwkoG1T)
What's happening in the example? ^

We declare the password to be "password"
We ask the user to enter his/her password
if the user-entered password is "password" , grant access.
could i have that in a loop program???
closed account (LzwkoG1T)
Like for the user to re-enter the password till he gets it right?

something like this:

while( userEnteredPassword != ActualPassword )
{

cin >> userPassword;

}

You can use the above code itself.
1
2
3
4
5
while( pwd != password )
{
  cout << "try again" << endl;
  cin >> pwd;
}
Topic archived. No new replies allowed.