How to stop access to program if login is failed

How to stop access to program if login is failed, like after the third try i attempt, stop the entire program( make the next line appear only if login is successful ) . Cause my current program still works, after 3 try of failed attempt of logging in

Thanks alot ! appreciated

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
 string userID, password; // For login
	const string stdUserID="test123";
	const string stdPassword="test1234";
	int i=0;

	cout<<"Welcome to xxx Calculator"<<endl;

	cout <<"----------Login Screen------------\n"; //For login 

	while ( i < 3 )

	{
		cout<<"To use xxx Calculator, please login !"<<endl; 
		cout <<"Please enter your userID:\t";
		cin>>userID;

		cout <<"Please enter your password:\t";
		cin>>password;

		if (userID.compare (stdUserID) ==0 && password.compare (stdPassword) ==0 )
		{
			system("COLOR 5");
    printf("Login successful ! \n");
 		break; // exit loop after display welcome message

		}

		else

		{

			cout <<"You have entered an invalid user ID or password , please try again \n" ;
			i++;

		}

	}

	if (i==3)

		cout <<"\nYou have reached maximum number of trials.  Access Denied! \n" ;


	while(loop=='Y' || loop=='y') // how to ensure that this part do not appear if there is failed attempt in logging in
	{

	cout <<"Please enter the ultimate tensile strength (UTS) of material needed ( highest 1000 ): " ;
	cin >>strength;
Last edited on
because the only thing you do after 3 failed attempts is tell the user. you still need to stop the rest of the program executing..
1
2
3
4
5
6
7
8
if (i==3) // enters here at failed attempt
{
    cout <<"\nYou have reached maximum number of trials.  Access Denied! \n" ;
}
else  // which means it doesnt enter here
{
    while(loop=='Y' || loop=='y') // how to ensure that this part do not appear if there is failed attempt in logging in
}


Isnt this what you want?
Last edited on
hey thanks tarikneaj, i got it!
Topic archived. No new replies allowed.