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);
}