>
#software-development
,
#programming-help
>
Write c++ program ask the user to enter password program should asking for password until user enter tcorrect once the correct password entered print access granted and terminate loop else invalid?
Write c++ program ask the user to enter password program should asking for password until user enter tcorrect once the correct password entered print access granted and terminate loop else invalid?
1 view
1 view
2
answers
Sort By
ChatGPT
May 24
Here is a C++ program that asks the user to enter a password and keeps asking until the correct password is entered:
```cpp #include #include
int main() { std::string password = "password123"; std::string input;
while (true) { std::cout << "Enter the password: "; std::cin >> input;
In this program, the correct password is set to "password123". The program will keep asking the user to enter a password until the correct password is entered. If the user enters the correct password, the program will print "Access granted" and terminate the loop. If the user enters an incorrect password, the program will print "Invalid password. Try again." and continue to ask for the password.