Hi Coders!!!
I am developing a Bank Management System ..In one of its provided facility i.e.new account creation i am having problem with gets(name) .

void account::create_account()
 {
     cout<<"\nEnter The account No.";
     cin>>acno;
     cout<<"\nEnter The Name of The account Holder :\n";
     gets(name);
     cout<<"Your name is :";
     puts(name);      //for check purpose but got it empty every time
     cout<<"\nEnter Type of The account (C/S) : ";
     cin>>type;
     type=toupper(type);
     cout<<"\nEnter The Initial amount(>=500 for Saving and>=1000       for current ) : ";
     cin>> dep;
     while(type=='C' && dep<1000)
       {
     cout<<"Please enter amount >=1000";
     cout<<"\n";
     cin>>dep;
       }
     while(type=='S'&& dep<500)
      {
      cout<<"Please enter amount >=500";
      cout<<"\n";
          cin>>dep;
       }
  cout<<"\n\n\nAccount Created..";
  cout<<"Good Luck :-)" ;
}

The Problem is that when i runs this program it asks for other inputs except "name" which it skips i.e. the cursor even doesn't bother to get to the line and so did i am unable to give name.
Please suggest me the possible reason
thanks in ADVANCE

i use getline(cin,name);
but problem will still exist until you clear the buffer .

write this to clear the buffer :

cin.ignore(numeric_limits<streamsize>::max(), '\n');

don't forget to include <limits>.

please correct me if i'm wrong.

i wanna know the reason for this if u can let me know ?

Because after you enter a number from the keyboard you have to press the <Return> or <Enter> key. That key, '\n' remains in the kayboard buffer until the next input is made. In the case of another number, cin skips all leading whitespace characters (space, newline, tab, and backspace) then process the remaining keys up to the first non-numeric digit. But, in the case of character array cin starts with the first character it finds in the keyboard buffer (which is now '\n') and stops when it finds end-of-data or a newline. Since the newline is the first character in the buffer cin won't do anything.

The way to solve that problem is to clear the keyboard buffer before calling cin. There is a thread here that explains how to do that in great detail.

Thanks for Providing me an INSIGHT to this Problem but the issue i m is still facing...I am unable to get to the line gets(name) i.e when i enters account no.after being asked the Compiler drives me to enter account type...

void account::create_account()
{
    cout<<"\nEnter The account No.";
    cin>>acno;
    cout<<"\nEnter The Name of The account Holder :\n";
    gets(name);
    cout<<"Your name is :";
    puts(name);      //for check purpose but got it empty every time
    cout<<"\nEnter Type of The account (C/S) : ";
    cin>>type;​

577e49283d99d40ce07934914debf115

In your screenshot, no name has been entered.

why are you mixing gets() and puts() which are C functions with cin and cout which are c++??? Be consistent, use either C or C++ fuctions but not both.

Replace gets() with getline() and puts() with cout.

Since you didn't post the rest of the program there is no way I can test it myself.

Also, you did not clear the keyboard buffer after entering the account number as you were instructed in previous posts. Can't help you if you fail to read and/or follow instructions.

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.