Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Password.cpp // Write a while loop to be used to test a password. The passwor

ID: 3597886 • Letter: #

Question

// Password.cpp //

Write a while loop to be used to test a password. The password is "secret" and the code within the loop is //executed until the user inputs the correct password.

#include #include using namespace std; int main(){ string passwd; string answer = "secret"; int count = 0; cout << "Please enter your password: "; cin >> passwd; while (passwd != answer) { cout << "Wrong password"; } cout << "Welcome Back "; return 0; }

I need help comparing two strings in order to verify a password with the string "secret" in C++

Explanation / Answer

#include <iostream>

#include<cstring>

using namespace std;
int main(){
string passwd;
string answer = "secret";
int count = 0;
cout << "Please enter your password: ";
cin >> passwd;
while (passwd != answer) {
cout << "Wrong password. ";
cout << "Please enter your password: ";
cin >> passwd;
count++;

}
cout << "Welcome Back ";
return 0;
  
}

Output: