do while loop problem

This is a discussion on do while loop problem within the C Programming forums, part of the General Programming Boards category; Hi everybody, I am back for help and advise, this time I do have problem with my loop.The loop is ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    do while loop problem

    Hi everybody,

    I am back for help and advise, this time I do have problem with my loop.The loop is exited when the user type "0"(zero) or the same batter number(double entry), but didn't work!I have to find way to exit the loop and call the next fuction to generate adn print my table, after the array is fill up. Here is my code:

    Code:
    struct batters get_entry (struct batters data[])
    {
        int i;
    	int id_batter; 
        
    	do  
    	 {
            
    	printf("Enter batter number:");
    		scanf("%i",&data[i].id_batter);
    		printf("Enter number of hits:");
            scanf("%i", &data[i].hits); 
            printf("Enter number of walks:"); 
            scanf("%i", &data[i].walks);
            printf("Enter number of outs:"); 
            scanf("%i", &data[i].outs);
            printf("Enter 0 to exit program\n");
    		++i
            
    	 }
    	 
    	while (id_batter != 0 || id_batter != id_batter);
    
    	return (data[i]);
    }
    Thanks !

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Change
    Code:
    (id_batter != 0 || id_batter != id_batter)
    to
    Code:
    (id_batter != 0 && id_batter != id_batter)
    To exit the loop with the first condition both conditions have to be false. To exit with the condition I gave only one has to be false.
    Last edited by Thantos; 11-30-2003 at 08:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM

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