I'm creating a password system for an encryption program.
For this i moved my main chunk of code inside an if statement, however now, instead of reading the code line by line, it simply prints it all at once. (e.g. when it comes to std::cout << "Enter here: "; std::getline(std::cin, userin);
the user cant input anything, it just prints the next line and keeps going.
int main(){
std::string userin;
std::string pass;
int attempts = 3;
std::cout << " ENCRYPTER" << std::endl;
std::cout << " " << std::endl;
while (attempts > 0){
std::cout << "Please Enter the Password" << std::endl;
if(attempts > 1){
std::cout << "You have " << attempts << " attempts remaining." << std::endl;
}
else {
std::cout << "You have " << attempts << " attempt remaining." << std::endl;
}
std::cin >> pass;
std::cout << " " << std::endl;
if(pass == "12345"){
std::cout << greetingFunc() << std::endl;
std::cout << " " << std::endl;
std::cout << "NOTE: Use only LETTERS. No numbers or grammar." << std::endl;
std::cout << " " << std::endl;
std::cout << "Please enter the message you wish to encrypt." << std::endl;
std::cout << "Enter here: "; std::getline(std::cin, userin);
std::cout << " " << std::endl;
std::cout << "Encrypted Message: " << encryptFunc(userin) << std::endl;
std::cout << " " << std::endl;
std::cout << "Highlight it and right click to copy." << std::endl;
system("pause");
} else {
std::cout << "Incorrect password. Please try again." << std::endl;
attempts--;
}
}
return 0;
}
Here is what is received in the console after the password is correctly entered.
Welcome to the Code Encrypter
NOTE: Use only LETTERS. No numbers or grammar.
Please enter the message you wish to encrypt.
Enter here:
Encrypted Message:
Highlight it and right click to copy.
Press any key to continue . . .
See how it just prints everything without running the functions or allowing the user to input their data.
How can i get it to read each line and stop to let the user input the info, and then proceed to call the encryption function? Thanks.