Hello... I'm practicing c++ and I'm trying to create a program with register and login in it.. the problem is I'm trying to compare the register username/password to the login username/password but even though the comparisons are right it's not working..

#include <Windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

struct First{

	string user;
	struct{
		char username[10];
		char password[10];
	}signup;

	struct{
		char username2[10];
		char password2[10];
	}login;

	struct{
		char firstname[50];
		char lastname[50];
	}name;

};

int option=0;
int inlog;

int main () 
{
	First A;
	cout << "LOADING PROGRAM...";
	Sleep (2000);
	cout << ".....";
	Sleep (2000);
	cout << ".....";
	Sleep (3000);
	cout << ".....";
	Sleep (2000);
	cout << ".....";
	Sleep (1000);

	cout << "" << endl;

	system("cls");
	cout << "**********************************************" << endl;
	cout << "WELCOME TO  OUR PROGRAM! PLEASE CHOOSE FROM THE CHOICES BELOW:" << endl;
	cout << "[1] REGISTER" << endl;
	cout << "[2] LOG-IN" << endl;
	cout << "**********************************************" << endl;
	cout << "Enter your choice here: ";
	cin >> option;

	if (option == 1)
	{
		system("cls");
		cout << "LOADING...";
		Sleep (2000);
		cout << ".....";
		Sleep (2000);
		cout << ".....";
		Sleep (3000);
		cout << ".....";

		cout << "" << endl;

		system("cls");
		cout << "==============================================" << endl;
		cout << "REGISTER BELOW:" << endl;
		cout << "==============================================" << endl;
		cout << "ENTER FIRST NAME: ";
		cin >> A.name.firstname;
		cout << "ENTER LAST NAME: ";
		cin >> A.name.lastname;
		cout << "ENTER USERNAME (UP TO 10 CHARACTERS LONG): ";
		cin >> A.signup.username;
		cout << "ENTER PASSWORD (UP TO 10 CHARACTERS LONG): ";
		cin >> A.signup.password;
		cout << "==============================================" << endl;

		cout << "" << endl;

		system("cls");
		cout << "PROCESSING...";
		Sleep (2000);
		cout << ".....";
		Sleep (2000);
		cout << ".....";
		Sleep (3000);
		cout << "....." << endl;

		system("cls");
		cout << "CONGRATULATIONS! YOU ARE NOW REGISTERED!" << endl;
		cout << "Want to Log-in? Press [2]." << endl;
		cin >> option;
		if (option == 2)
		{
			system("cls");
			cout << "LOADING...";
			Sleep (2000);
			cout << ".....";
			Sleep (2000);
			cout << ".....";
			Sleep (3000);
			cout << ".....";

			cout << "" << endl;

			system("cls");
			cout << "==============================================" << endl;
			cout << "LOG-IN BELOW:" << endl;
			cout << "==============================================" << endl;
			cout << "ENTER USERNAME: ";
			cin >> A.login.username2;
			cout << "ENTER PASSWORD: ";
			cin >> A.login.password2;
			cout << "==============================================" << endl;

			cout << "" << endl;

			system("cls");
			cout << "PROCESSING...";
			Sleep (2000);
			cout << ".....";
			Sleep (2000);
			cout << ".....";
			Sleep (3000);
			cout << "....." << endl;

			cout << "" << endl;

			system("cls");
			if(A.signup.username != A.login.username2 && A.signup.password != A.login.password2)
			{
				cout << "OOPS! SEEMS LIKE YOUR USERNAME OR PASSWORD IS WRONG!" << endl;
			}
			else if(A.signup.username == A.login.username2 && A.signup.password == A.login.password2)
			{
				cout << "CONGRATULATIONS! YOU ARE NOW LOGGED IN!" << endl;
				cout << "LOADING...";
				Sleep (2000);
				cout << ".....";
				Sleep (2000);
				cout << ".....";
				Sleep (3000);
				cout << ".....";

				system("cls");
				cout << "WELCOME, " << A.login.username2 << "!" << "YOU'VE OPENED OUR PROGRAM! YAY!" <<endl;
			}
		}
		else {
			cout << "WRONG INPUT!" << endl;
		}
	}
	else if (option == 2)
	{
		system("cls");
		cout << "LOADING...";
		Sleep (2000);
		cout << ".....";
		Sleep (2000);
		cout << ".....";
		Sleep (3000);
		cout << ".....";

		cout << "" << endl;

		cout << "==============================================" << endl;
		cout << "LOG-IN BELOW:" << endl;
		cout << "==============================================" << endl;
		cout << "ENTER USERNAME: ";
		cin >> A.login.username2;
		cout << "ENTER PASSWORD: ";
		cin >> A.login.password2;
		cout << "==============================================" << endl;

		cout << "" << endl;

		system("cls");
		cout << "PROCESSING...";
		Sleep (2000);
		cout << ".....";
		Sleep (2000);
		cout << ".....";
		Sleep (3000);
		cout << ".....";

		cout << "" << endl;

		system("cls");
		if(A.signup.username != A.login.username2 && A.signup.password != A.login.password2)
		{
			cout << "OOPS! SEEMS LIKE YOUR USERNAME OR PASSWORD IS WRONG!" << endl;
		}
		else if(A.signup.username == A.login.username2 && A.signup.password == A.login.password2)
		{
			cout << "CONGRATULATIONS! YOU ARE NOW LOGGED IN!" << endl;
			cout << "LOADING...";
			Sleep (2000);
			cout << ".....";
			Sleep (2000);
			cout << ".....";
			Sleep (3000);
			cout << ".....";

			system("cls");
			cout << "WELCOME, " << A.login.username2 << "!" << "YOU'VE OPENED OUR PROGRAM! YAY!" <<endl;
		}
	}
	else if (option == 3){

	}
	else{
		cout << "WRONG INPUT!" << endl;
	}
	}
	system("pause > 0");
	return 0;
}

Please help me..

Recommended Answers

All 4 Replies

You can not use != or == operator to compare two character arrays, you have to call strcmp() to do that if( strcmp(A.signup.username,A.login.username2) != 0)

You can not use != or == operator to compare two character arrays, you have to call strcmp() to do that if( strcmp(A.signup.username,A.login.username2) != 0)

Hi Ancient Dragon! I tried the string compare code and it's still not working. :(

If you don't mind me asking, why are you using C-style strings for the username, password, etc., when you've already used a string for the user variable? Wouldn't using a C++ style string be much easier?

Also, I would recommend breaking your program up into separate functions, especially the login operation, which you actually have in two different places that I can see.

Also, your program is not saving the Registered name/password anywhere, so when you start the program and just select Login where is the registered name/password supposed to come from?

And what's with all those Sleep()s? The program isn't actually doing anything when it displays "Loading ..." so why waste everyone's time with that nonsense.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.