Forloop

This is a discussion on Forloop within the C++ Programming forums, part of the General Programming Boards category; Hello, im writtign a program that will process basketball data. The ending file will look like this: CONFERENCE OVERALL Rank ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    Exclamation Forloop

    Hello, im writtign a program that will process basketball data. The ending file will look like this:


    CONFERENCE OVERALL
    Rank Team W-L % WINS MARGIN W-L % WINS MARGIN
    1 WILM 3-1 0.750 +7.25 7-2 0.778 +10.00
    1 OTT 3-1 0.750 +14.00 5-4 0.556 +7.56
    1 ONU 3-1 0.750 +15.25 7-2 0.778 +17.78
    1 CAP 3-1 0.750 +11.75 7-2 0.778 +13.67
    1 BW 3-1 0.750 +10.50 8-1 0.889 +13.56
    6 MUC 2-2 0.500 -6.25 4-4 0.500 -0.50
    7 MUSK 1-2 0.333 -12.00 5-3 0.625 +2.63
    8 HEID 1-3 0.250 -4.00 3-4 0.429 +1.57
    9 MAR 0-4 0.000 -29.75 2-7 0.222 -10.89
    9 JCU 0-3 0.000 -13.00 2-5 0.286 -3.00

    I need a for loop that wil compare the % wins and if the are the same to store the same rank in the array else store the corresponding rank.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So, sort the data, and check to see if the current team's win pct is the same as the previous team's win pct (which you must have stored somewhere).

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    Yes, i have stored and stored it in parllel arrays.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    i used a bubble sort, so the highest would be in cell number 9 and the lowest is in cell 0
    when iuse a backward for loop the current count is not the count i need. So the when i get to memory cell 0, i would need a rank of 9 rather than a 1 or a 0. So i think i would need to use two forloops. right?
    Last edited by mmiskand; 12-02-2008 at 05:38 PM.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's a little awkward, since that's the wrong way around (you want the highest winning percentage first). But otherwise, you're done -- check against the previous team, and if their win pct is the same, assign this team the same rank as the old team, otherwise assign this team the rank i+1 (or whatever your loop counter is).

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    ok, so i think i might need to change the sort i used.

  7. #7
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    You could just change the comparison operator you're using '<' vs. '>' in your bubble sort, and it should be sorted in the reverse order of you're sorting it now.
    Programming Your Mom. http://www.dandongs.com/

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    Code:
    int pointsTemp, conferenceWinstemp,winsTemp, loseTemp, pointsloseTemp, conferenceLosetemp, conferencePointsTemp, conferencePointsloseTemp;					// temp place to store element during swap
    float totalAvarageTemp, avaregeTemp;
    string nameTemp;
    	
    	int swaps;					// swaps made in single pass
    	int slot = 9;				// start at last slot
    	do					
    	{
    		swaps = 0;				// have made no swaps yet in this pass
    		for (int i = 0; i< slot; i++)		// for all elements above this slot
    			if (ConferenceAvarege[i] < ConferenceAvarege[i-1])		// if in wrong relative order
    			{
    				avaregeTemp = ConferenceAvarege[i];		// swap them
    				ConferenceAvarege[i] = ConferenceAvarege[i-1];
    				ConferenceAvarege[i-1] = avaregeTemp;
    
    				nameTemp = school.name[i];		// swap them
    				school.name[i] = school.name[i-1];
    				school.name[i-1] = nameTemp;
    				
    				
    				conferenceWinstemp = school.conferenceWins[i];		// swap them
    				school.conferenceWins[i] = school.conferenceWins[i-1];
    				school.conferenceWins[i-1] = conferenceWinstemp;
    
    				conferenceLosetemp = school.conferenceLose[i];		// swap them
    				school.conferenceLose[i] = school.conferenceLose[i-1];
    				school.conferenceLose[i-1] = conferenceLosetemp;
    				
    
    				conferencePointsloseTemp = school.conferencePointslost[i];		// swap them
    				school.conferencePointslost[i] = school.conferencePointslost[i-1];
    				school.conferencePointslost[i-1] = conferencePointsloseTemp;
    				
    
    				conferencePointsTemp = school.conferencePoints[i];		// swap them
    				school.conferencePoints[i] = school.conferencePoints[i-1];
    				school.conferencePoints[i-1] = conferencePointsTemp;
    				
    
    				winsTemp = school.wins[i];		// swap them
    				school.wins[i] = school.wins[i-1];
    				school.wins[i-1] = winsTemp;
    				
    
    				loseTemp= school.lose[i];		// swap them
    				school.lose[i] = school.lose[i-1];
    				school.lose[i-1] = loseTemp;
    				
    
    				pointsTemp = school.points[i];		// swap them
    				school.points[i] = school.points[i-1];
    				school.points[i-1] = pointsTemp;
    				
    				pointsloseTemp = school.pointsLost[i];		// swap them
    				school.pointsLost[i] = school.pointsLost[i-1];
    				school.pointsLost[i-1] = pointsloseTemp;
    
    				totalAvarageTemp = Totalavarage[i];		// swap them
    				Totalavarage[i] = Totalavarage[i-1];
    				Totalavarage[i-1] =totalAvarageTemp;
    						
    				
    										
    				
    				swaps++;		// note that a swap was made
    			}
    		slot--;					// get ready to do next slot up
    	}while (slot>0&& swaps>0);

    I changed all my comparsion to the oppsite and put minus where plus was. Is that right?

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    no, sorry. I just did it right. Thank you. Can you help me do the for loop to do the rank

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-09-2009, 07:17 PM
  2. Arrary & ForLoop
    By slimdime in forum C++ Programming
    Replies: 32
    Last Post: 05-15-2008, 08:12 PM
  3. I have problem with for(loop)
    By LINUX in forum C++ Programming
    Replies: 5
    Last Post: 03-24-2007, 04:19 PM
  4. Simple array/pointer problem...
    By smoothdogg00 in forum C Programming
    Replies: 3
    Last Post: 03-15-2006, 12:00 PM

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