#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 


{

    char bname[97],number[34],code[22], name[10],bcate[10],pass,book,author,ID,school,course ;   
    char type, address[5],x,department,quantity,choice,date[10],aname[20],btitle[50], bcode[9] ;
    int getch();
    int num1,num2,num3,num4,num5,num6,num7,num8,op,a, ph[20],num,i=0;
    int input[10];







    cout<<"\t\tWELCOME TO OUR LIBRARY"<<endl;
    cout<<""<<endl;
    cout<<"Enter Username"<<endl;
    cin>>name;
    cout<<""<<endl;
    cout<<"ENTER PASSWORD"<<endl;

                   for(num=0;;)
      {
         a=getch();

         if((a>='a' && a<='z')||(a>='A' && a<='Z')||(a>='1' && a<='9'))
         {
               ph[num]=a;
               cout<<"*";
               ++num;
               }

         if(a=='\r')
         {
           ph[num]='\0';
           break;
           }      
           }

           if(pass=='input')
            {
                  cout<<"PASSWORD ACCEPTED"<<endl;
            }
 if(pass=='else') 
 {
    cout<<"Login rejected"<<endl;
 }
    cout<<""<<endl;
    cout<<""<<endl;
    cout<<""<<endl;


     cout<<"\t\tOUR SERVICES IS AS FOLLOWS"<<endl;

        cout<<""<<endl;
        cout<<"\t\t1.Enter a new book"<<endl;
        cout<<""<<endl;
        cout<<"\t\t2.create student record"<<endl;
        cout<<""<<endl;
        cout<<"\t\t3.Buy Book"<<endl;
        cout<<""<<endl;
        cout<<"\t\t4.Find Book"<<endl;
        cout<<""<<endl;
        cout<<"\t\t5.Display Books"<<endl;
        cout<<""<<endl;
        cout<<"\t\t6.Borrow books"<<endl;
        cout<<""<<endl;
    cout<<"\t\t7.TO RETURN BOOK"<<endl;
     cout<<""<<endl;
     cout<<"\t\t8.DONATE BOOKS"<<endl;

    cout<<""<<endl; 

    cout<<"\t\tSelect An Option"<<endl;
        cin>>input[10];





    if(input[10]==1)
    {
    cout<<"\t\t1.NEW BOOK ENTRY"<<endl; 
    cout<<""<<endl;
    cout<<"\t\t*PLEASE FILL THE FORM AND PRESS 'ENTER' AFTER EVERY INPUT*"<<endl;    
    cout<<""<<endl;

    cout<<"Enter Book Title"<<endl;
    cin>>btitle;
    cout<<""<<endl;

    cout<<"Enter Author name"<<endl;
    cin>>aname;
    cout<<""<<endl;

    cout<<"Enter Book code"<<endl;
    cin>>bcode;
    cout<<""<<endl;

    cout<<"Category of book"<<endl;
    cin>>bcate;


    cout<<"\nNEW BOOK ENTRY SUCCESSFUL"<<endl;
}


if(input[10]==2)

cout<<"\t\tEnter ID number"<<endl;
            cin>>ID;
            cout<<""<<endl;
            cout<<"\t\tEnter  Name"<<endl;
            cin>>name;
            cout<<""<<endl;
        cout<<"\t\tEnter school name or institution name"<<endl;
        cin>>school;
        cout<<"\t\tEnter address"<<endl;
        cin>>address;

        cout<<""<<endl;
         cout<<"\t\tcourse title"<<endl;
         cin>>course;
         cout<<"\t\t\nRECORD CREATED SUCCESSFULLY!!"<<endl;

    if(input[10]==3)
    {   
    cout<<"WELCOME PURCHASE A BOOK"<<endl;  
         cout<<"ENTER YOUR NAME"<<endl;
          cin>>name;
          cout<<"ENTER CARD NUMBER"<<endl;
          cin>>number;

    cout<<"ENTER CARD NAME"<<endl;
    cin>>name;
          cout<<"ENETR BOOK NAME YOU WANT TO BUY"<<endl;          
          cin>>bname;

          cout<<"ENTER BOOK CODE"<<endl;
          cin>>code;

          cout<<"ENTER ADDRESS"<<endl;
          cin>>date;

          cout<<"QUANTITY YOU WANT BUY"<<endl;
          cin>>quantity;

          cout<<"THANKS FOR PURCHASING"<<endl;
          }

            if(input[10]==4)
            {
    cout<<"\t\tEnter book name"<<endl;
            cin>>name;
            cout<<""<<endl;
            cout<<"\t\tOR"<<endl;
            cout<<""<<endl;
        cout<<"\t\tEnter Author name"<<endl;
        cin>>name;
        cout<<"\t\tOR"<<endl;
         cout<<""<<endl;
         cout<<"\t\tInput book code"<<endl;
         cin>>code;
         }


        if(input[10]==5)
        {           
            cout<<"Linguistics"<<endl;
        cout<<""<<endl;
        cout<<"MANAGEMENT STUDIES"<<endl;
        cout<<""<<endl;
        cout<<"PROGRAMMING METHOD"<<endl;
        cout<<""<<endl;
        cout<<"MORPHOLOGY"<<endl;
        cout<<""<<endl;
        cout<<"HISTORY"<<endl;
        cout<<""<<endl;
        cout<<"SPORTS LEADERSHIP"<<endl;
        cout<<""<<endl;
        cout<<"Social Studies"<<endl;
        cout<<""<<endl;
        cout<<"Mathematics"<<endl;
        cout<<""<<endl;
        cout<<"Coaching"<<endl;
        cout<<""<<endl;
        cout<<"Resaerch Method"<<endl;
        cout<<""<<endl;
        cout<<"Sex Education"<<endl;
        }

       if(input[10]==6)
       {                                    
            cout<<"ENTER YOUR NAME"<<endl;
          cin>>name;                    
          cout<<"ENTER DEPARTMENT"<<endl;
          cin>>department;      
    cout<<"ENTER COURSE NAME"<<endl;
    cin>>name;
     cout<<""<<endl;
          cout<<"ENETR BOOK NAME YOU WANT BORROW"<<endl;          
          cin>>bname;
           cout<<""<<endl;
          cout<<"ENTER BOOK CODE"<<endl;
          cin>>code;
         cout<<""<<endl;
          cout<<"ENTER ADDRESS"<<endl;
          cin>>date;
           cout<<""<<endl;
          cout<<"ENTER PHONE NUMBER"<<endl;
          cin>>number;
           cout<<""<<endl;
          cout<<"ENTER DATE OF TAKING BOOK"<<endl; 
          cin>>date;
          cout<<"*BOOK SHOULDNT BE TAKEN FOR MORE THAN 1WEEK*"<<endl;
           cout<<""<<endl;
           cout<<"DATE OF RETURN TO BE GIVEN TO YOU AT THE RECEPTION"<<endl;
           }


            if(input[10]==7)
            {                               
                cout<<"ENTER YOUR NAME"<<endl;
          cin>>name;          
          cout<<"ENETR BOOK NAME YOU WANT TO RETURN"<<endl;          
          cin>>bname;
           cout<<""<<endl;
          cout<<"ENTER BOOK CODE"<<endl;
          cin>>code;
         cout<<""<<endl;
           cout<<""<<endl;
          cout<<"ENTER DATE BOOK WAS BORROWED"<<endl; 
          cin>>date;
          cout<<"ENTER DATE OF RETURNING BOOKS"<<endl;
          cin>>date;
           cout<<""<<endl;
           cout<<"PLEASE SIGN A BOOK AT THE RECEPTION BEFORE LEAVING"<<endl;
           }


          if(input[10]==8)
          {       
                 cout<<"Please enter your name"<<endl;
             cin>>name;

              cout<<""<<endl;
               cout<<"please enter your address"<<endl;
               cin>>address;

               cout<<"Please enter book type(s) you wnat to donate"<<endl;
               cin>>type;

               cout<<""<<endl;
                cout<<"Please enter quantity you would like to donate"<<endl;
                 cin>>quantity; 

                 cout<<""<<endl;
                cout<<"Please leave the book(s) at the library reception"<<endl;
                      cout<<""<<endl;

                cout<<"THANK YOU FOR DONATING!:)"<<endl;          




}

system("Pause");
    return 0;   
}

Hi guys this is the code i wrote for a library,i have tried adding the password feature to it but when i input a wrong password and username it still takes me to the program instead rejecting it and if i input the correct one too it still takes me to the program, i would like you guys to help me solve the problem, like when i input a wrong password it shouldnt open the program it should reject the login and when i input the correct one it should it should accept and give me access to the program. Thank you.

The only thing your code is doing once the password is checked, is telling the user whether it's valid or not. I would suggest a bool and a while loop:

string name = "";
string ph = "";
bool done = false;
while (!done)
{
    cout << "Enter Username\n";
    cin >> name;
    cout << "" << endl;
    cout << "ENTER PASSWORD\n";
    cin >> ph;
    if (ph == 'input')
    {
        done = true;
        cout << "PASSWORD ACCEPTED\n";
    }
    else
    {
        cout << "Login rejected\nTry again.\n";
    }
}
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.