I`m trying to to use if statement but something going wrong.
statement must be 2 steps
IF There is still room in the array and
IF there is not an Appointmen on the same Date and Time!
Apointment will be accept......
im not getting any error or worning
but its not chaking second if statement and both else printing together
void addAppointmenRecords( )
{
int number, i,k;
system("cls"); //clear screen
cout<<"\nHow many Appointmen you wish to add? ";
cin>>number; //read number
cin.get(); //read newline character left in the buffer
if((number + currentSize ) <= listSize) //There is still room in the array
{
for( i = 1; i<=number; i++ )
{
cout<<"\nEnter Person name: ";
getline(cin, AppointmenList[currentSize].name);
cout<<"Enter Appointmen Descriptions: ";
getline(cin, AppointmenList[currentSize].description);
cout<<"Enter Appointmen date: ";
cin>>AppointmenList[currentSize].appdate.day;
cin>>AppointmenList[currentSize].appdate.mounth;
cin>>AppointmenList[currentSize].appdate.year;
cin.get(); //read a character
cout<<"Enter Appointmen time: ";
getline(cin, AppointmenList[currentSize].time);
cout<<endl;
currentSize += 1; //update CurrentSize
for(k=0; k<currentSize; k++) //chech if there an Appointmen on the same Date and Time!
if( AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
AppointmenList[currentSize].time == AppointmenList[k].time )
{
cout<<"\nGot a match\n";
cout<<"Appointmen Date and Time already filled"<<endl;
currentSize-=1;
}
else
{
cout<<"Apointment accepted"<<endl;
currentSize+=1;
}
}
}
else
{
cout<<"Overflow!!!! Appointmen List is full"<<endl;
cout<<"\nPress any key to continue"<<endl;
cin.get(); //read a character
}
}
void addAppointmenRecords( )
{
int number, i,k;
system("cls"); //clear screen
cout<<"\nHow many Appointments do you wish to add? ";
cin>>number; //read number
cin.get(); //read newline character left in the buffer
if((number + currentSize ) <= listSize)//There is still room in the array
{
for( i = 1; i<=number; i++ )
{
cout<<"\nEnter Person name: ";
getline(cin, AppointmenList[currentSize].name);
cout<<"Enter Appointment Descriptions: ";
getline(cin, AppointmenList[currentSize].description);
cout<<"Enter Appointment date: ";
cin>>AppointmenList[currentSize].appdate.day;
cin>>AppointmenList[currentSize].appdate.mounth;
cin>>AppointmenList[currentSize].appdate.year;
cin.get();//read a character
cout<<"Enter Appointment time: ";
getline(cin, AppointmenList[currentSize].time);
cout<<endl;
currentSize += 1; //update CurrentSize
for(k=0; k<currentSize; k++) //check if there an Appointmen on the same Date and Time!
{
if(AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
AppointmenList[currentSize].time == AppointmenList[k].time )
{
cout<<"\nGot a match\n";
cout<<"Appointment Date and Time already filled"<<endl;
currentSize-=1;
}
else
{
cout<<"Apointment accepted"<<endl;
currentSize+=1;
}
}
}
}
else
{
cout<<"Overflow!!!! Appointment List is full"<<endl;
cout<<"\nPress any key to continue"<<endl;
cin.get(); //read a character
}
}
You were missing a couple of brackets in there, I'm supprised it compiled. All fixed along with spelling and grammar corrections on the couts. Use spaces instead of tabs, it makes it alot easier to keep track of your bracketing, all you have to do is press the up or down arrow from one bracket to another to see which bracket begins and ends which statement, and thats important if you are using alot of ifs and elses inside each other.
void addAppointmenRecords( )
{
int number, i,k;
system("cls"); //clear screen
cout<<"\nHow many Appointments do you wish to add? ";
cin>>number; //read number
cin.get(); //read newline character left in the buffer
if((number + currentSize ) <= listSize)//There is still room in the array
{
for( i = 1; i<=number; i++ )
{
cout<<"\nEnter Person name: ";
getline(cin, AppointmenList[currentSize].name);
cout<<"Enter Appointment Descriptions: ";
getline(cin, AppointmenList[currentSize].description);
cout<<"Enter Appointment date: ";
cin>>AppointmenList[currentSize].appdate.day;
cin>>AppointmenList[currentSize].appdate.mounth;
cin>>AppointmenList[currentSize].appdate.year;
cin.get();//read a character
cout<<"Enter Appointment time: ";
getline(cin, AppointmenList[currentSize].time);
cout<<endl;
currentSize += 1; //update CurrentSize
for(k=0; k<currentSize; k++) //check if there an Appointmen on the same Date and Time!
{
if(AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
AppointmenList[currentSize].time == AppointmenList[k].time )
{
cout<<"\nGot a match\n";
cout<<"Appointment Date and Time already filled"<<endl;
currentSize-=1;
}
else
{
cout<<"Apointment accepted"<<endl;
currentSize+=1;
}
}
}
}
else
{
cout<<"Overflow!!!! Appointment List is full"<<endl;
cout<<"\nPress any key to continue"<<endl;
cin.get(); //read a character
}
}
Cleaned up the indentation on it to make it look cleaner. LOT easier to read.
void addAppointmenRecords( )
{
int number, i,k;
system("cls"); //clear screen
cout<<"\nHow many Appointments do you wish to add? ";
cin>>number; //read number
cin.get(); //read newline character left in the buffer
if((number + currentSize ) <= listSize)//There is still room in the array
{
for( i = 1; i<=number; i++ )
{
cout<<"\nEnter Person name: ";
getline(cin, AppointmenList[currentSize].name);
cout<<"Enter Appointment Descriptions: ";
getline(cin, AppointmenList[currentSize].description);
cout<<"Enter Appointment date: ";
cin>>AppointmenList[currentSize].appdate.day;
cin>>AppointmenList[currentSize].appdate.mounth;
cin>>AppointmenList[currentSize].appdate.year;
cin.get();//read a character
cout<<"Enter Appointment time: ";
getline(cin, AppointmenList[currentSize].time);
cout<<endl;
currentSize += 1; //update CurrentSize
for(k=0; k<currentSize; k++) //check if there an Appointmen on the same Date and Time!
{
if(AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
AppointmenList[currentSize].time == AppointmenList[k].time )
{
cout<<"\nGot a match\n";
cout<<"Appointment Date and Time already filled"<<endl;
currentSize-=1;
break;
}
else
{
cout<<"Apointment accepted"<<endl;
currentSize+=1;
}
}
}
}
else
{
cout<<"Overflow!!!! Appointment List is full"<<endl;
cout<<"\nPress any key to continue"<<endl;
cin.get(); //read a character
}
}