preblem with if statements

This is a discussion on preblem with if statements within the C Programming forums, part of the General Programming Boards category; i am very new to programming and desperately need help. I have an ssignment to make a football league table. ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    7

    preblem with if statements

    i am very new to programming and desperately need help. I have an ssignment to make a football league table. you need to enter teams, enter results and have a table dipslay results.
    when i try to display results my program shuts down. I am obvoiusly doing something incorrect but i cant see what it is. This is the function affected:

    Code:
     void displayLeagueTable(struct league records[])
    {
    	int i;
    
    	for ( i = 0; i < MAXTEAMS; i++)
    	{
    		if (records[i].teamScore > records[i+1].teamScore)
    		{
    			records[i].points += 2;
    			records[i].won ++;
    			records[i].played++;
    			records[i+1].lost++;
    			records[i+1].points -= 1; 
    			records[i+1].played++;
    			
    		} 
    		if (records[i].teamScore < records[i+1].teamScore)
    		{
    			records[i+1].points += 3;
    			records[i+1].won ++;
    			records[i+1].played++;
    			records[i].lost++;
    			records[i].points -= 1; 
    			records[i].played++;
    			
    		}
    		if (records[i].teamScore == records[i+1].teamScore)
    		{
    			records[i].points += 1;
    			records[i].won ++;
    			records[i].played++;
    			records[i+1].lost++;
    			records[i+1].points += 1; 
    			records[i+1].played++;
    		}
    	}
    Any help would be very much appreciated.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    for ( i = 0; i < MAXTEAMS; i++)
    The loop should propably run to i < MAXTEAMS -1 because you compare records[i] with records[i+1]

    Kurt

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    7
    thank you so much, it no longer crashes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 11:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 12:36 PM
  4. having problems with my if statements
    By bajanstar in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 01:39 PM
  5. Class Function Members and If Statements
    By Team Shadow V2 in forum C++ Programming
    Replies: 10
    Last Post: 02-03-2005, 03:00 PM

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