illegal Else ???

This is a discussion on illegal Else ??? within the C++ Programming forums, part of the General Programming Boards category; can any one see my mistakes for illegal else and //chech if there an Appointmen on the same Date and ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    24

    Arrow illegal Else ???

    can any one see my mistakes for illegal else and
    //chech if there an Appointmen on the same Date and Time!
    seems not working
    Code:
    void addAppointmenRecords( )
    {  
    	int number, i;
    	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(int 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;
    				break;
    			else 
    			
    				cout<<"Appointmen accepted"<<endl;
    			currentSize+=1;		
    		}
    	else
    		cout<<"Overflow!!!! Appointmen List is full"<<endl;
    		cout<<"\nPress any key to continue"<<endl;
    		cin.get();     //read a character 
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,620
    Yeah. You're assuming that indenting code is enough to tell the compiler that code should be grouped. It is not.

    The code;
    Code:
    if (X())
        a();
        b();
    else
        c();
    actually looks to the compiler like
    Code:
    if (X())
        a();
    
    b();
    else
    c();
    The call of b() is not one of the statements affected by the if() statement. And the else keyword does not match anything.

    You need to learn to use braces {} to group lines of code, not indenting with whitespace. Because the compiler ignores whitespace (except in character strings).

    You have several examples of this sort of thing in your code needing fixing.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    thaks grumpy i fixed like this, im not getting any error or worning now but i still have problem.
    what is wrong with my
    //chech if there an Appointmen on the same Date and Time!
    Code:
    void addAppointmenRecords( )
    {  
    	int number, i;
    	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(int 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<<"Appointmen accepted"<<endl;
    				currentSize+=1;
    			}
    	}
    }
    	else
    	{
    		cout<<"Overflow!!!! Appointmen List is full"<<endl;
    		cout<<"\nPress any key to continue"<<endl;
    		cin.get();     //read a character
    	}
    }

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What is wrong with what? If you at least explain what sort of problem we are looking for, we can help a bit better?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    sorry matsp
    this is my entry

    How many Appointmen you wish to add? 2

    Enter Person name: zafer
    Enter Appointmen Descriptions: lunch
    Enter Appointmen date: 12 12 2009
    Enter Appointmen time: 12:30

    Appointmen accepted

    Got a match
    Appointmen Date and Time already filled

    Enter Person name: zafer
    Enter Appointmen Descriptions: dinner
    Enter Appointmen date: 12 12 2009
    Enter Appointmen time: 20:30
    Appointmen accepted

    Got a match
    Appointmen Date and Time already filled
    its not checking if there an Appointmen on the same Date and Time!
    and
    Appointmen accepted
    and
    Got a match
    Appointmen Date and Time already filled
    fallowing each other. i couldent work out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C2100 Illegal Indirection error?
    By dnguyen1022 in forum C++ Programming
    Replies: 1
    Last Post: 06-18-2009, 11:47 PM
  2. Replies: 3
    Last Post: 05-24-2009, 03:42 AM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM
  5. Illegal Characters
    By Echidna in forum Windows Programming
    Replies: 3
    Last Post: 12-08-2002, 04:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21