Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jadi gini, ku mau buat program username-password sederhana.
- proses yang direncanakan kek gini:
- di fungsi main, parameter username sama password di set.
- naah pas program di 'run'
- user akan memasukkan input:
- 1. un, apabila un == username, lanjutkan ke; jika tidak, ulangi
- 2. pw, apabila pw == password, program selesai; jika tidak, ulangi.
- */
- #include <iostream>
- #include <string>
- using namespace std;
- class req
- {
- public:
- string username;
- string password;
- string getUn()
- {
- return username;
- }
- void setUn(string username)
- {
- this->username = username;
- }
- string getPw()
- {
- return password;
- }
- void setPw(string password)
- {
- this->password = password;
- }
- void enterName()
- {
- string un;
- cout << "Username: ";
- cin >> un;
- if(un == username)
- {
- enterPassword();
- }
- else if (un != username)
- {
- cout << "wrong, try again!" << endl;
- enterName();
- }
- }
- void enterPassword()
- {
- string pw;
- cout << "Password: ";
- cin >> pw;
- if(pw == password)
- {
- cout << ", Good to go!";
- }
- else if (pw != password)
- {
- cout << "wrong, try again!" << endl;
- enterPassword();
- }
- }
- };
- int main()
- {
- req myself;
- myself.setUn("self");
- myself.setPw("idklol");
- req oof;
- oof.enterName();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement