i couldnt figure out this any help anyone?????
it should checked if there an Appointment on the same Date and Time! but its not. i can still put more then 1 record on the same date and time????

void addAppRecords( )
{
	int number;
	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(int i = 1; i<=number; i++)
	   {
		 cout<<"\nEnter Person name: ";
		 getline(cin, AppList[currentSize].name);
		 cout<<"Enter Appointment Descriptions: ";
		 getline(cin, AppList[currentSize].description);
		 cout<<"Enter Appointment date: ";
		 cin>>AppoList[currentSize].appdate.day;
		 cin>>AppList[currentSize].appdate.mounth;
		 cin>>AppList[currentSize].appdate.year;
		 cin.get();            //read a character
		 cout<<"Enter Appointment time: ";
		 getline(cin, AppointmentList[currentSize].time);
		 cout<<endl;
		 currentSize += 1;    //update CurrentSize
		 for(int k=0; k<=currentSize; k++)
		  {       //check if there an Appointment on the same Date and Time!
		    if(AppList[currentSize].appdate.day == AppList[k].appdate.day && 
	                AppList[currentSize].appdate.mounth == AppList[k].appdate.mounth && 
                         AppList[currentSize].appdate.year == AppList[k].appdate.year && 
                         AppList[currentSize].time == AppList[k].time )
			  {
			    cout<<"\nGot a match\n";
			    cout<<"Appointment Date and Time already filled"<<endl;
			    currentSize -= 1; //update CurrentSize
			    cin.get();
			  }
		     else
			  {
			    cout<<"Apointment accepted"<<endl;
			    cin.get();     //read a character
			    break;
			  }
		 }
	  }
	}
   else
	 {
	   cout<<"Overflow!!!! Appointment List is full"<<endl;
	   cout<<"\nPress any key to continue"<<endl;
	   cin.get();     //read a character
	 }
}

Recommended Answers

All 9 Replies

Ooh... You have incremented currentSize just before the search/accept/reject loop so the last appointment index is currenSize-1 in the loop!..

So where do i need to incremented currentSize then??

So where do i need to incremented currentSize then??

Increment it wherever you like but think about correct index of a new record in the loop.

Increment it wherever you like but think about correct index of a new record in the loop.

i tried to move

currentSize -= 1;

but didnt work i can still add records on sama date and time????

It seems you don't understand me. Even worse, it seems you don't understand your own code.

After currentSize+=1 you have currentSize elements from AppoList[0] to AppoList[currentSize-1] . No AppoList[currenSize] element in this array at all! Array indices in C++ are started from 0, not from 1. So in the loop you are trying to refer to unexisting array element.

That's your problem: wrong index. It's not a problem: where to increment currenSize.

Please, next time use code tag properly:
[code=cplusplus] source

[/code]

ArkM
Thats right i dont understand too much yet. i started to learn c++ not long ago. im still a beginer. i dont have too much experience like you.

So do you mean my codes never gonna work this way????

void addAppointmentRecords( )
{  
    int number;
    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(int i = 1; i<=number; i++)
		 {
		    cout<<"\nEnter Person name: ";
		    getline(cin, AppList[currentSize].name);
		    cout<<"Enter Appointment Descriptions: ";
		    getline(cin, AppList[currentSize].description);
		    cout<<"Enter Appointment date: ";
		    cin>>AppList[currentSize].appdate.day;
		    cin>>AppList[currentSize].appdate.mounth;
		    cin>>AppList[currentSize].appdate.year;
		    cin.get();//read a character
		    cout<<"Enter Appointment time: ";
		    getline(cin, AppList[currentSize].time);
		    cout<<endl;
		    for(int k=0; k<currentSize; k++)  //check if there an Appointment on the same Date and Time!
		      {
		        if( AppList[currentSize].appdate.day == AppList[k].appdate.day && 
		            AppList[currentSize].appdate.mounth == AppList[k].appdate.mounth && 
		            AppList[currentSize].appdate.year == AppList[k].appdate.year && 
		            AppList[currentSize].time == AppList[k].time )
				{
				   cout<<"\nGot a match\n";
				   cout<<"Appointment Date and Time already filled"<<endl;
				   currentSize -= 1; //update CurrentSize
				   cin.get();
				}
		       else
				   cout<<"Apointment accepted"<<endl;
				   cin.get();     //read a character
				   break;
			 }
			       currentSize += 1;
		 }
	 }
	else
	 {
	    cout<<"Overflow!!!! Appointment List is full"<<endl;
	    cout<<"\nPress any key to continue"<<endl;
	    cin.get();     //read a character
	 }
}

That's it! You have a good chance to win...
Try this then report us ;)...

>im still a beginer. i dont have too much experience like you.
Alas, I have a lots of my own C++ problems when my code size exceeds ~100000 lines ;)

That's it! You have a good chance to win...
Try this then report us ;)...

i can report just now my codes working %100

i can report just now my codes working %100

Congratulation! Good job.

Next time try to overload operator== and operator>>(istream&...) for appdate+time structure ;)...

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.