problem with cin>> cin.getline

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2005
Posts: 42
Reputation: TimC is an unknown quantity at this point 
Solved Threads: 0
TimC TimC is offline Offline
Light Poster

problem with cin>> cin.getline

 
0
  #1
Dec 3rd, 2005
I have 2 functions in my main(). When I call the first function void patient_main_menu(); it will leave me input all the required fields and it also will print to screen EXACTLY what I had inputed originally.

When the second function is called void doctor_main_menu(); it SKIPS/ Will not leave me INPUT the first field. I dont understand what I am doing wrong as it should be similar to the 1st function.

thx in advance for any advice

TIm
(main file attached for clarity)


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "patient.h"
#include "list.h"
#include "doctor.h"

void patient_main_menu();
void doctor_main_menu();

doctor DA[5];
static int i=0;
    
int main(int argc, char *argv[])
{
  
  
  patient_main_menu();
  
  doctor_main_menu();
  
  
  system("PAUSE");	
  return 0;
}



void patient_main_menu()
{

  char name[30];
  char dob[10];
  char illness[20];
  int t=1;
  int priority;
  int wardno;
  
  Sequence S;
  patient P;

  cout<<"Enter name of Patient:"<<endl;
  cin.getline(name,30);
  P.set_Name(name);
  
  cout<<"Enter Date of Birth eg 20/11/76:"<<endl;
  cin.getline(dob,10);
  P.set_dob(dob);
  
  cout<<"Enter Illness:"<<endl;
  cin.getline(illness,20);
  P.set_illness(illness);  
  
  cout<<"Enter Priority:"<<endl;
  cin>>priority;
  P.set_priority(priority); 
  
  cout<<"Enter Ward No:"<<endl;
  cin>>wardno;
  P.set_ward_no(wardno);   
        
  S.insert(t,P);    
  S.display();

}

void doctor_main_menu()
{

  char newname[20];
  char address[50];   
  int age;   
  int hours;   
  int payrate; 
  
 
  
  cout<<"Enter name of Doctor:"<<endl;                               //Problem is here with my cin //       cin.getline(newname,20);
  DA[i].set_Name(newname);
  
  cout<<"Enter Address:"<<endl;
  cin.getline(address,50);
  DA[i].set_Address(address);
  
  cout<<"Enter Age:"<<endl;
  cin>>age;
  DA[i].set_Age(age);  
  
  cout<<"Enter Hours Worked:"<<endl;
  cin>>hours;
  DA[i].set_Hours(hours); 
  
  cout<<"Enter Payrate:"<<endl;
  cin>>payrate;
  DA[i].set_Payrate(payrate); 
 
   
  cout<<DA[i].get_Name();
  cout<<DA[i].get_Address();
}
Last edited by Dave Sinkula; Dec 3rd, 2005 at 5:07 pm. Reason: Added [code][/code] tags.
Attached Files
File Type: zip 4.zip (143.9 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: problem with cin>> cin.getline

 
0
  #2
Dec 3rd, 2005
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 42
Reputation: TimC is an unknown quantity at this point 
Solved Threads: 0
TimC TimC is offline Offline
Light Poster

Re: problem with cin>> cin.getline

 
0
  #3
Dec 4th, 2005
that link solved my problem,

thx
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC