the only problem in this code is i must use longer username and password like for example dani and the password is web, not d and w only. this is very easy but i didn't make it, please help me with this. In this program, after you log in you will proceed to the menu, if you failed to log in 3 times login failed will appear and it will exit.

#include<iostream>
#include<string.h>
using namespace std;


void menu();
void unpw();

void main()
{
	unpw();
}

void unpw()
{
	char arrun[100];
	char arrpw[100];
	char a;
	char b;
	string cprogra;
	string dlsl;
	

	a='d';
	b='w';
	
	
	cout<<"Enter Username:  ";
	cin>>arrun[100];
	cout<<"Enter Password:  ";
	cin>>arrpw[100];
	system("cls");

	
	if(arrun[100]==a)
	{
		menu();
	}
	if(arrun[100]!=a)
	{
		cout<<"Invalid Username or Password";
		cout<<endl;

		system("pause");
		system("cls");
			
	}
	
	cout<<"Enter Username:  ";
	cin>>arrun[100];
	cout<<"Enter Password:  ";
	cin>>arrpw[100];
	system("cls");
		if(arrun[100]==a)
	{
		menu();
	}
	
	if(arrun[100]!=a)
	{
		cout<<"Invalid Username or Password";
		cout<<endl;

		system("pause");
		system("cls");	
	}

	cout<<"Enter Username:  ";
	cin>>arrun[100];
	cout<<"Enter Password:  ";
	cin>>arrpw[100];
	system("cls");
		if(arrun[100]==a)
	{
		menu();
	}

	if(arrun[100]!=a)
	{
		cout<<"Log in failed!!"<<endl;
		cout<<endl;

		system("pause");
		system("cls");
		exit(0);
	}
	
	if(arrpw[100]==b)
	{
		menu();
	}
	if(arrpw[100]!=b)
	{
		cout<<"Invalid Username or Password";
		cout<<endl;

		system("pause");
		system("cls");
	}

	cout<<"Enter Username:  ";
	cin>>arrun[100];
	cout<<"Enter Password:  ";
	cin>>arrpw[100];
	system("cls");
		if(arrpw[100]==b)
	{
		menu();
	}
	
	if(arrpw[100]!=b)
	{
		cout<<"Invalid Username or Password";
		cout<<endl;

		system("pause");
		system("cls");
	}
	
	cout<<"Enter Username:  ";
	cin>>arrun[100];
	cout<<"Enter Password:  ";
	cin>>arrpw[100];
	system("cls");
		if(arrpw[100]==b)
	{
		menu();
	}
	
	if(arrpw[100]!=b)
	{
		cout<<"Log in failed!!!!"<<endl;
		cout<<endl;

		system("pause");
		system("cls");
		exit(0);
	}
		




}
void menu()
{
	int i;
	
	
	
		cout<<"Menu"<<endl;
		cout<<"[1]--Add"<<endl;
		cout<<"[2]--Search"<<endl;
		cout<<"[3]--View"<<endl;
		cout<<"[4]--Exit"<<endl;
		cout<<"Enter your choice(1,2,3,4): ";
		cin>>i;
		system("cls");
		
		switch(i)
		{
		case 1:
			cout<<"Add"<<endl;
			cout<<endl;

			system("pause");
			system("cls");
			break;
		case 2:
			cout<<"Search"<<endl;
			cout<<endl;

			system("pause");
			system("cls");
			break;
		case 3:
			cout<<"View"<<endl;
			cout<<endl;

			system("pause");
			system("cls");
			break;
		case 4:
			cout<<"Are you sure?(y or n):";
			cin>>choice;
			system("cls");
			break;
		default:	
			cout<<"\n\nInvalid!!";
			system("pause");
			break;
		}
	}
	exit(0);
}

Edited 5 Years Ago by Narue: Added code tags

if you want 'a' and 'b' to be able to hold more than one character, then change them to something like this:

char a[x] //where x is any number you choose.
char b[y] //where y is any number you choose.

as for the 3 attempts before a fail thing, you'll want to use a loop for that. probably a do loop. the way this program is currently set up is where it does not use a loop for the prompting of the username/password.

This should be good info to get you started. ;)

Edited 5 Years Ago by Derek Elensar: n/a

The statements on lines 29 and 31, among others, are nonsense. If you do not understand why, please study your textbook until you do. This is too fundamental a misunderstanding to be worth spending the time to explain.

This article has been dead for over six months. Start a new discussion instead.