Thread: infinite loop-having trouble debugging

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Did you say beer ? ... actually a good ol' glass of iced tea would probably do much better.

    To get rid of the duplicate display. At the end of LoadArray(), you have a call to DisplayArray():
    length = counter-1;
    sorted = false;
    DisplayArray(list,length); //delete this line

    >I could probably do a lot of those couts through the switch statements, is there any preference on how that is done?

    I agree with you, for example the Smallest(), Largest(), and Average() functions. Since you are returning the value anyway, why not print it in ProcessChoice? Of course with the Sort() function, the way you have done it is best.

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    infinite loop

    Ice tea it is, sweet tea of course.

    I am about to try the file input after having cleared up the small details on the other.

    Keep your fingers crossed.

    I took out the DisplayArray after the first LoadArray call, and left the DisplayArray at the end of the LoadArray function. Seems to work ok.

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Ice tea it is, sweet tea of course.
    Sweet tea is the best.

    Have fun cleaning up the details ... and ... yes a little sleep will be nice about now.

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    infinite loop

    when I sort, it misses one of the numbers

    0. -22.0
    1. -13.5
    2. 4.0
    3. 8.0
    4. 8.0
    5. 8.0
    6. 21.0
    7. 21.0
    8. 21.0
    9. 21.0
    10. 61.0
    11. 61.0
    12. 21.0
    13. 67.1


    see number 12? why is that near the bottom?

  5. #20
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I input:
    2, 1, and 3, and it exhibits the same problem ... will not sort. Looks like a bug in the sort function.

  6. #21
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    Smile infinite loop

    Thanks for all your help. I will work more on it tomorrow before class and after the kids are off to school.

    Get some sleep!

  7. #22
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I don't know what kind of sort you are using. The only one I know is the bubble sort. If you can use the bubble sort, I think this will work:
    Code:
    void Sort(float list[],
    		  int length)
    {
    	float	temp;
    	int		passCount;
    	int		searchIndex;
    
    	for(passCount = 0; passCount<length-1; passCount++)
    	{
    		for(searchIndex=passCount+1; searchIndex<length;searchIndex++)
    		{
    			if(list[searchIndex] < list[passCount])
    			{
    				temp = list[passCount];
    				list[passCount] = list[searchIndex];
    				list[searchIndex] = temp;
    			}
    
    		}
    	}
    	sorted = true;
    	DisplayArray(list, length);
    }
    Also, there is a built in quicksort in c++. You may not be allowed to use this. It's callled qsort.
    Signing off til tomorrow afternoon.
    Last edited by swoopy; 12-11-2001 at 02:56 AM.

  8. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    16

    infinite loop

    That sort worked perfectly! I am having a little difficulty with the file input but should be able to work that out.

    thanks again for all your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 04:45 AM
  3. infinite loop with signal chaining
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 04-18-2008, 10:14 AM
  4. infinite loop error
    By tsubasa in forum C Programming
    Replies: 7
    Last Post: 05-24-2006, 02:37 PM
  5. infinite loop problem
    By Gil22 in forum C++ Programming
    Replies: 3
    Last Post: 03-07-2003, 03:24 PM