Site icon DataFlair

C++ Project – Login Application

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Login Application 
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#define clrscr() system("cls")
using namespace std;
int main()
{
    clrscr();
    char username[20];
    char ch1,ch2,ch3,ch4;
    static int countlogin=0;
    user:cout<<"\n Enter user name: ";
    cin>>username;
     cout<<"\n Enter password( Only 4 Character): ";
    countlogin++;
    ch1=getch();
    cout<<"*";
    ch2=getch();
    cout<<"*";
    ch3=getch();
    cout<<"*";
    ch4=getch();
    cout<<"*";
 if((strcmp(username,"vivek")==0) && (ch1=='1' && ch2=='2' && ch3=='3' && ch4=='4')) 
 {
     
    clrscr();
    cout<<"\n **************Game for Ramdom Number Guess **********";
    srand(time(NULL));
    int comp,user;
    int count=5;
    int i=0,choice;
do
{
    comp=rand()%100;
    while(count)
    {
        i++;
       cout<<"\n Enter a number for guess: You have "<< count <<" chance left";
        cin>>user;
     if(user==comp)
     {
         cout<<"\n ******Congrats You won the game in "<< i <<" Chances *****";
         break;
     }
     else
      if(user>comp)
      cout<<"\n  Your number is grater";
      else
      cout<<"\n  Your number is less" ;
      count--;
    }
    if(count==0)
    {
        cout<<"\n Oops you lose the game.. all chances finish !";
        cout<<"\n Computer genrated no is : "<<comp;
    }
 cout<<"\n You want to play more.!(For Yes Press 1 for No Press 0)";
 cin>>choice;
}while(choice!=0);   
cout<<"\n Thanks for playing Bye Bye !";
 }
 else
 {
   cout<<"\n Invalid user id or password";
   if(countlogin==3)
  { 
     cout<<"\n User login is locked contact to admin";
     exit(0);
  }   
   goto user;
 }
    return 0;
}

 

Exit mobile version