QUERY

Create a call by referencefunction program that takes user ID (in integer) and password (in integer) as inputs. If default ID and password is wrong,then show a message that incorrect user ID and password otherwise show you are successfully login and change the password. Once the password has been changed, login again with the same ID and new password. It must be login successfully and ask again to change the password. In case of incorrect password, program STOP
OK, so where is your attempt?

This isn't a homework on demand service, where you can simply copy/paste your tutor assignment.
Only for you to then copy/paste an answer back to your tutor, while you pretend that you learnt something in the process.

To give you an idea,

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>

struct User
{
	int userID;
	int password;
};

bool inputUserName(User&, int, int, const int);
void inputUserPassword(User&, int, int, const int, bool&);

int main()
{
	User user;
	int defaultUserID {12345};
	int defaultPassword {9876};
	int count{0};
	const int numOfTries{3};

	bool correctIDMatch{ inputUserName(user, defaultUserID, count, numOfTries) };

	bool correctPassMatch{ false };

	if (correctIDMatch)
	{
		inputUserPassword(user, defaultPassword, count, numOfTries, correctPassMatch);
	}
	else
	{
		std::cout << "Your account is locked\n";
		return 0;
	}

	if (correctIDMatch == correctPassMatch)
	{
		std::cout << "Login succesful for UserID: " << user.userID << std::endl;
		std::cout << "Please change your password.\n";
		std::cout << "Password: ";
		std::cin >> defaultPassword;
	}
	else
		std::cout << "Your account is locked\n";

	return 0;
}
bool inputUserName(User& user, int defaultUserID, int count, const int numOfTries)
{
	bool matched{false};

	std::cout << "UserID: ";
	std::cin >> user.userID;

	while (count < numOfTries)
	{
		if (user.userID != defaultUserID)
		{
			count++;
			std::cout << "Wrong UserID!!!\n";
			std::cout << "Number of tries left: " << numOfTries - count << std::endl;

			std::cout << "Username: ";
			std::cin >> user.userID;
		}
		else
		{
			matched = true;
			break;
		}

	}

	return matched;
}

void inputUserPassword(User& user, int defaultUserPassword, int count, const int numOfTries, bool& matched)
{

	std::cout << "Password: ";
	std::cin >> user.password;

	while (count < numOfTries)
	{
		if (user.password != defaultUserPassword)
		{
			count++;
			std::cout << "Wrong Password!!!\n";
			std::cout << "Number of tries left: " << numOfTries - count << std::endl;

			std::cout << "Password: ";
			std::cin >> user.password;

		}
		else
		{
			matched = true;
			break;
		}

	}

}
Topic archived. No new replies allowed.