+ 1

make a program to check password entered by user

24th Jul 2016, 6:47 PM
padmesh
padmesh - avatar
3 Answers
+ 2
#include <iostream> using namespace std; int main () { string password,enteredpass; password = "mypassword"; cout<<"Please enter password"; cin>>enteredpass; if (password == enteredpass) { cout<<"Right password!You may now use the program"; } else cout<<"Wrong password! Try again.."; } This is basic..This is what i understood from what you asked. By the way, add whatever you want at the if
24th Jul 2016, 6:56 PM
Vlad Cranga
Vlad Cranga - avatar
+ 2
this same code as previous one but i have made it loop until u enter the correct password #include <iostream> using namespace std; int main () { string password,enteredpass; password = "mypassword"; do { cout<<"Please enter password"; cin>>enteredpass; if (password == enteredpass) { cout<<"Right password!You may now use the program"; } else cout<<"Wrong password! Try again.."; }while(enteredpass != " mypassword" ); return 0; }
24th Jul 2016, 7:31 PM
Dinesh C
Dinesh C - avatar
+ 1
Good add,didnt think about that when i wrote it.
24th Jul 2016, 7:34 PM
Vlad Cranga
Vlad Cranga - avatar