if else statement ????

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
			}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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.
closed account (S6k9GNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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.
sorry for my codes i tryed to clean a bit.
its not checking
if there an Appointmen on the same Date and Time!

and printing
"Apointment accepted"

and
Got a match
Appointment Date and Time already filled

can anybody see mistakes now??????

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
	 }
}
Topic archived. No new replies allowed.