Weegee
Go Weegee!
- Reaction score
- 102
Hello! I was playing around in VC++ 2010 and tried to make a makeshift "Username and Password" program. Here is the code:
After a while of playing around with values, this code works when you input the username and password for one of the two "accounts", HOWEVER when I input lets say the values "a" and "a" for username and password, the program just sits there and doesnt respond (picture attached). What I want the program to accomplish is that if you enter the values for an already made "account" it responds and says hello, however, if you enter a false (non-existent) account, I want it to reply "username and password do not match" or whatever . Anyone see what I did wrong in the "username and password do not match" part of my code ? And if you have any tips on what I should change in my code to make it better (leak proof, faster, more understandable, etc) please dont hesitate to say so! (Yes I know my code is horrible, I was just playing around with things )
PHP:
// Example use of a data structure
#include <iostream>
#include <Windows.h>
#include <string.h>
#include <string>
using namespace std;
struct accountinfo {
string accountname;
string accountpassword;
};
accountinfo Bob;
accountinfo Joe;
int main ()
{
Bob.accountname = "bob";
Bob.accountpassword = "password1";
Joe.accountname = "joe";
Joe.accountpassword = "password2";
string username;
string password;
bool done = false;
do
{
if (username == Bob.accountname && password == Bob.accountpassword || username == Joe.accountname && password == Joe.accountpassword)
{
if (username == Bob.accountname && password == Bob.accountpassword)
{
cout << "Welcome, Bob" << endl;
system ("Pause");
}
else if (username == Joe.accountname && password == Joe.accountpassword)
{
cout << "Welcome, Joe" << endl;
system ("Pause");
}
else
{
cout << "Username and Password does not match" << endl;
system ("Pause");
}
}
else {
while (done == false)
{
cout << "Please enter a username registered on the program: " << endl;
cin >> username;
cout << "Now Please enter the password that is for your account: " << endl;
cin >> password;
done = true;
}
}
} while (done == true);
return 0;
}
After a while of playing around with values, this code works when you input the username and password for one of the two "accounts", HOWEVER when I input lets say the values "a" and "a" for username and password, the program just sits there and doesnt respond (picture attached). What I want the program to accomplish is that if you enter the values for an already made "account" it responds and says hello, however, if you enter a false (non-existent) account, I want it to reply "username and password do not match" or whatever . Anyone see what I did wrong in the "username and password do not match" part of my code ? And if you have any tips on what I should change in my code to make it better (leak proof, faster, more understandable, etc) please dont hesitate to say so! (Yes I know my code is horrible, I was just playing around with things )