breaking a loop

i need the loop to break when i enter the new password.
right now whenever i enter the new password, it shows " your password has been changed" and it goes back to " Please enter your 4 - digit password ". i want it to end on " your password has been changed ". help

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
#include <iostream>
using namespace std;
void main()
{  
 
        int userID = 0;
        int password = 0; 
        int newpassword = 0;
 
 
		cout << "Please enter your 6-digit user id: "; 
        cin >> userID;
		for ( int c=3; c>0; c--)
		if (userID == 286957)
		{
			cout << "Please enter your 4-digit password: ";
			cin >> password;
			for ( int c=3; c>0; c--)
			if (password == 2468)
			{
		
				cout << "Logged in successfully. You should change your password at the first login. \nThe new password should be a 4-digit number and different from \nthe current password. ";
				cout << "Please enter your new 4-digit password: ";
				cin >> newpassword;
				cout << "Your password has been changed \n";
				
			}
			

			else	
			{
				cout << "Invalid userID/password. You can try "<< c << " more time/s \n";
				cin >> password;
			}
			break;
		}
		else 
		{ 
			cout << "Invalid userID/password. You can try "<< c << " more time/s \n";
			cin >> userID;
		}
		system ("pause");
}
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
#include <iostream>
using namespace std;
int main()
{  
 
        int userID = 0;
        int password = 0; 
        int newpassword = 0;
 
 
		cout << "Please enter your 6-digit user id: "; 
        cin >> userID;
		for ( int c=3; c>0; c--)
		if (userID == 286957)
		{
			cout << "Please enter your 4-digit password: ";
			cin >> password;
			for ( int c=3; c>0; c--)
			if (password == 2468)
			{
		
				cout << "Logged in successfully. You should change your password at the first login. \nThe new password should be a 4-digit number and different from \nthe current password. ";
				cout << "Please enter your new 4-digit password: ";
				cin >> newpassword;
				cout << "Your password has been changed \n";
				break;
				
			}
			

			else	
			{
				cout << "Invalid userID/password. You can try "<< c << " more time/s \n";
				cin >> password;
			}
			break;
		}
		else 
		{ 
			cout << "Invalid userID/password. You can try "<< c << " more time/s \n";
			cin >> userID;
		}
		system ("pause");
}


i need the loop to break when i enter the new password.


you answered it, put a break when you want it to break.
Last edited on
oh god.. I'm an idiot.. haha thank you!
i just spent 4 hours to fix an assignment that only needed one more line to fix.

so i know how it feels. goodluck with you codes.
Topic archived. No new replies allowed.