Sorry...Made a change after that. Just learned do while loops. Is this correct? Though I did use at least 1 goto because I dunno how to do 'do while' loop twice. Like this?
I removed the cin.ignore() after getline(), but still I can't input the username, only can input password.
Code:
//Answer to page 71 Q 4, chapter 4: If Statements
#include <iostream>;
#include <string>;
using namespace std;
string username;
string password;
string choice;
int main()
{
do {
cout << "Username: ";
getline(cin, username);
cout << "Password: ";
getline( cin, password);
if ( username == "Johnny" && password == "x" || username == "Debb" && password == "y" || username == "Oh hai" && password == "z")
{ cout << "Valid password. You may now enter paradise.\n"; }
else
{ cout << "Invalid username or password. Please try again.\n If you forgot your password, ask for help at nearby abyss's sinner support.\n\n";
choice:
cout << "Do you want to try filling in the username and password again? y/n \n\n";
cin >> choice;
}
}
while ( choice == "y" && choice != "n");
if ( choice != "y" && choice != "n" )
{ cout << "Invalid choice.\n";
goto choice; }
system("pause");
return 0;
}
Thank you for replying.