Question
I have this c++ code where it generates random passwords and asks the user to enter their guesses for the random passwords. I am trying
I have this c++ code where it generates random passwords and asks the user to enter their guesses for the random passwords. I am trying to apply these two if statements;
Allow the user to repeat step the number of guesses until they either get the password totally correct, or they decide they give up.
#include
#include
#include
using namespace std;
int main()
{
// DON'T CHANGE THESE FIRST 2 LINES, which are used to get the random numbers loaded
int time = clock(); // Stores the computer's time in the variable time
srand(time); // Primes the pump for the random number generator
// const string UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWZ"
char alphabet[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int length;
int GiveUp = 0;
string password = "",guess;
cout << "How long is the password you want to create: ";
cin >> length;
if (length != 0)
{
cout << "Your desired length is:" << length << endl;
}
for(int i = 0; i < length; i++)
{
password += alphabet[rand() % 26];
}
cout< //Printed because it is hard to guess as the code doesn't pick a meaningful password //It picks random letters cout<<" Guesses Screen "; while(true) { int c=0; cin>>guess; for(int i = 0; i < length; i++) { if(guess[i]==password[i]) { c=c+1; cout< } else cout<<"_ "; } cout<<" "< if(c==length)//if all the letters are correct you break { cout<<" YOU WIN!!"; break; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started