The program asks the user to enter physician name as array of character,but do not work properly ,only work for single character how can i input array of character for the physician name.
look case 1 on my code.
for( i=0;i<n;i++)
{
cout<<"\nEnter physician "<<i+1 <<" name :";
cin>>phy_name[i];
cout<<"Enter physician "<<i+1<<" id :";
cin>>phy_id[i];
cout<<"Enter physician "<<i+1 <<" specification :";
cin>>phy_spec[i];
cout<<"Enter physician "<<i+1 <<"work experiance :";
cin>>phy_workex[i];
cout<<endl;
}
It only works for single character ,if I try to input array of character for example .
enter physician name >S.....it works but for
enter physician name>Sisay ..the loop goes infinite..
how can I solve the problem please correct it by adding some codes for me
************************************************
//program to write the information of patients registered
// and physician available in the hospital.The program asks
//the user to register physician,register patient,
//list all available physicians and lisit all registered patients
// depending on the interest of the user.
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int i;
char name[12],*nam=&name[0];
int ch,n,phy_id[100],phy_workex[100];
char phy_name[100],phy_spec[100];
char *phyname=&phy_name[0];
char pat_name[100],pat_gender[10],pat_case[50],ass_phy[12];
char *patname=&pat_name[0];
int m,pat_age[4],pat_cardno[20],pat_date[4];
do
{
cout<<"\t\t\t TASK SELECTION WINDOW \n";
cout<<"\t\t\t ********************* \n";
cout<<"\t\tWhat would you like to do ?\n";
cout<<"\t\t Please enter the number you choice \n";
cout<<"\t\t 1.Register a physician/s \n";
cout<<"\t\t 2.Register a patient/s \n";
cout<<"\t\t 3.List all available physicians \n";
cout<<"\t\t 4.List all registered patients \n";
cout<<"\t\t 5.Quit a program \n";
cout<<endl;
cout<<"Please enter your choice !\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\t How many physician you want to register ?\n";
cout<<"\t------------------------------------------\n";
cin>>n;
cout<<"Enter name,id,specification and work experiance of "<<n<<"physicians"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
for( i=0;i<n;i++)
{
cout<<"\nEnter physician "<<i+1 <<" name :";
cin>>phy_name[i];
cout<<"Enter physician "<<i+1<<" id :";
cin>>phy_id[i];
cout<<"Enter physician "<<i+1 <<" specification :";
cin>>phy_spec[i];
cout<<"Enter physician "<<i+1 <<"work experiance :";
cin>>phy_workex[i];
cout<<endl;
}
break;
case 2:
cout<<"\t How many patient you want to register ?\n";
cout<<"\t -------------------------------------- \n";
cin>>m;
cout<<"Enter name,age,gender,card no,case,date and assigned physician of"<<m<<"patients"<<endl;
cout<<"-------------------------------------------------------------------------"<<endl;
for( i=0;i<m;i++)
{
cout<<"\n Enter patient "<<i+1<<" name :";
cin>>pat_name[i];
cout<<"\n Enter patient "<<i+1<<" age :";
cin>>pat_age[i];
cout<<"\nEnter patient "<<i+1<<" gender :";
cin>>pat_gender[i];
cout<<"\n enter patient "<<i+1<<" card number :";
cin>>pat_cardno[i];
cout<<"\n Enter patient"<<i+1<<" case :";
cin>>pat_case[i];
cout<<"\n Enter patient "<<i+1<<" date :";
cin>>pat_date[i];
cout<<"\n Enter patient "<<i+1<<" assigned physician :";
cin>>ass_phy[i];
cout<<endl;
}
break;
case 3:
cout<<"\t program to list all available physicians \n";
cout<<"\t ---------------------------------------- \n";
cout<<"Number "<<" name "<<"\t"<<"ID" <<"\t"<<"specification "<<"\t"<<"work exepriance \n";
for(i=0;i<n;i++)
{
cout<< i+1<<"\t"<<phy_name[i]<<"\t"<<phy_id[i];
cout<<"\t"<<phy_spec[i]<<"\t\t"<<phy_workex[i];
cout<<endl;
}
break;
case 4:
cout<<"\t\tprogram to list all registered patients \n";
cout<<"\t\t****************************************\n";
cout<<"number "<<"\t"<<"age"<<"\t"<<"gender"<<"\t"<<"card number ";
cout<<"\t"<<"case"<<"\t"<<"date"<<"\t"<<"assigned physician";
cout<<endl;
for( i=0;i<m;i++)
{
cout<< i+1<<"\t"<<pat_name[i]<<"\t"<<pat_age[i]<<"\t"<<pat_gender[i];
cout<<"\t"<<pat_cardno[i]<<"\t"<<pat_case[i]<<"\t"<<pat_date[i];
cout<<"\t"<<ass_phy[i]<<endl;
}
break;
case 5:
cout<<"\tCongratulation you finished your program !\n";
cout<<"\t-----------------------------------------\n";
return 0;
break;
}
}
while(true);
return 0;
}