Thread: If/Else Problem

  1. #1
    Registered User Vireyda's Avatar
    Join Date
    Mar 2004
    Posts
    26

    Question If/Else Problem

    Hello,
    I'm having an issue with an if/else or maybe just the boolean conditions for it but I'm really stuck. But what my problem is that The print statement "There is no record matching etc..." is being called when it shouldn't so I would assume that 1 is being added t the count in the else if where it shouldn't if the employee muber is found. If feel like I muddled that whole sentence, but I'm not sure how else to explain it. Any help would be great.

    Thanks,
    Vireyda

    Code:
    		if(FindNumber == expenses[i].emp_num)
    		{
    
    			//prompt user for input from menu to choose field to update
    			printf("\nWhat would you like to update?");
    			printf("\nDistance Traveled\t- D or d\nMileage Rate\t\t- R or r\nMeal Costs\t\t- M or m\nQuit to Main Menu\t- Q or q");
    			fflush(stdin);
    			scanf("%c", &update);//assign user choice to variable update
    			
    			//switch to case based on the variable update as defined by the user
    			switch(update)
    			{
    //ommited for space
    			}//end swtich
    
    		}//end if
    		else if(FindNumber!=expenses[i].emp_num)//if input employee number does not match any record
    			++count;//add one to count
    
    		}//end for
    	if (count==i+1)//if count equals i+1
    		printf("\nThere is no record matching that employee number in the database.\n");

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Is this code within a for-loop? If yes, then once you find the matching employee number, you should break out of the for-loop. Otherwise, count will get incremented multiple times.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM