GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Mar-2005, 09:52
Networkedd Networkedd is offline
Awaiting Email Confirmation
 
Join Date: Mar 2005
Location: UK
Posts: 2
Networkedd is on a distinguished road

C league table


Hello!
I have been given an assignment to create a league table in C. Basically a series of match results are to be entered by the user and an updated league table is to be produced. Which looks something like this:

P W D L F A T
Galatasaray 2 1 1 0 4 3 4
Juventus 2 0 2 0 3 3 2
Rosenborg 2 0 2 0 2 2 2
Atlentico 2 0 1 1 2 3 1

I am uber new to this whole programming thing, my teacher here at uni is terrible, and I am really confused. I have spent hours trying to figure this out but so far all I have come up with is the main menus etc (which i am dead proud of!!!). I have also made an array for the team names which I can now add one at a time, and I figured that I have to make a 2d array for the scores part. At this point we don't have to worry about sorting them in any particular order, just trying to get it to display ^like that is hard enough.
Does anyone have any ideas how this could be done, and how I could display this table. Any help would be really appreciated as I am going nuts and have my first demo soon :-?
Thanks very much for taking the time to read this.

Edd 8-)

P.S: another thing: when I add a new team to the array, and display it, it shows a whole bunch of other stuff in the places where there aren't teams. Someone told me that, that is what was in memory before, but I cannot clear it. Any ideas?
  #2  
Old 13-Mar-2005, 10:29
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Networkedd
Hello!
Hi! Welcomne to GID!

Quote:
Originally Posted by Networkedd
I have been given an assignment to create a league table in C. Basically a series of match results are to be entered by the user and an updated league table is to be produced. Which looks something like this:

P W D L F A T
Galatasaray 2 1 1 0 4 3 4
Juventus 2 0 2 0 3 3 2
Rosenborg 2 0 2 0 2 2 2
Atlentico 2 0 1 1 2 3 1

I am uber new to this whole programming thing, my teacher here at uni is terrible, and I am really confused.
Wish we had a nickel for every time we hear that, eh JDS?

Quote:
Originally Posted by Networkedd
I have spent hours trying to figure this out but so far all I have come up with is the main menus etc (which i am dead proud of!!!). I have also made an array for the team names which I can now add one at a time, and I figured that I have to make a 2d array for the scores part. At this point we don't have to worry about sorting them in any particular order, just trying to get it to display ^like that is hard enough.
Yep, you've got the solution. You just have to read in the values and load them into the int array, one row per name.

Quote:
Originally Posted by Networkedd
Does anyone have any ideas how this could be done, and how I could display this table. Any help would be really appreciated as I am going nuts and have my first demo soon :-?
Absolutely. It's customary to post the portion of the code you are having trouble with so we can see what you're trying to do. Without the code it's like talking to your mechanic over the phone trying to describe that weird ping noise and expecting a solution. Be sure to read the sticky post at the top of this forum first.

Basically you will need two nested loops to accomplish this task. For example:
CPP / C++ / C Code:
while (x != b)
{
    // Read a line from the file and load the name into the name array
    while (y != c)
    {
     // This loop loads each value into your score array
    }
}
I leave it to you to figure out what test goes in each while() statement. Keep in mind this may not be your solution, just an idea to get you thinking.

Quote:
Originally Posted by Networkedd
Thanks very much for taking the time to read this.

Edd 8-)

P.S: another thing: when I add a new team to the array, and display it, it shows a whole bunch of other stuff in the places where there aren't teams. Someone told me that, that is what was in memory before, but I cannot clear it. Any ideas?
Definitely need to see code for this. I can describe what's happening but I can't give you a solution without more information on exactly your situation.

When any variable is defined in C/C++ the variable is not cleared to a known value unless it's global. So whatever happened to be in that memory location the variable is now defined at is the initial value of the variable. It's literally junk and needs to be cleared if you plan on using it without loading it, or just don't use it until it has been loaded with data.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #3  
Old 13-Mar-2005, 10:43
Networkedd Networkedd is offline
Awaiting Email Confirmation
 
Join Date: Mar 2005
Location: UK
Posts: 2
Networkedd is on a distinguished road

Code


Hi there,

Thanks for the swift reply, sorry about not posting the source code, silly of me
Cheers for your help, I appreciate it immensely

Edd

CPP / C++ / C Code:
/*menu.c - prohram to select simple functions from a menu*/
#include <stdio.h>

/************************************************************/
/*                       Prototypes                         */
/************************************************************/
char print_header(void);		//prints menu options
void read_teams(char [][21], int);
void print_teams(char [] [21], int);
/************************************************************/
/*                Main Function                             */
/************************************************************/
int main(void)
{
 char option, rtn;
 option = print_header();
 while(option != 'q' && option != 'Q')
 {
    switch(option)
      {
	case 'a': case 'A': /*Enter team */
		 printf("\nPlease Enter a new team:\n");
		 char list[12][21]; //20 chars each + '\0'
		 read_teams(list, 12);
		 break;
	case 'b': case'B': /*Display table*/
		 print_teams(list, 12);
		 break;
	case 'c': case'C': /*Match details*/
		 break;
	case 'd': case 'D': /*Exit*/
		 printf("\n*** FINISHED ***\n");
		 exit(0);
	default: /*invalid option letter entererd*/
		 printf("\nInvalid choice, Please try again\n");
     }
   option = print_header();
   }
  return 0;
}/*end main*/
/****************************************************************/
/*                      Functions                               */
/****************************************************************/
/****************************************************************/
/*                      Print Menu Options                      */
/****************************************************************/
char print_header(void)
{
   char opt,rtn;
   printf("\n****************************");
   printf("\n*     Football League    *");
   printf("\n****************************\n");
   printf("\na.\tEnter a New Team\n");
   printf("\nb.\tDisplay Current Table\n");
   printf("\nc.\tEnter Match Details\n");
   printf("\nd.\tExit System\n");
   printf("\nPlease Enter Your Choice: \n");
   scanf("%c%c",&opt,&rtn);
   return opt;
}


/****************************************************************/
/*                    Stores a new team                         */
/****************************************************************/
void read_teams(char s[][21], int n)
{
   static int i;
   printf("\nPlease enter a new team\n");
   {
	   gets(s[i]);
	   i++;
   }
}
/****************************************************************/
/*                  Displays the current teams                  */
/****************************************************************/
void print_teams(char list[][21], int n)
{
	int i;
	printf("\nThe current Teams are:\n\n");
	for (i=0; i<n; i++)
	{  //print each row list [i] as string
		printf("%s\n", list[i]);
	}
}
/****************************************************************/
/*																*/
/****************************************************************/
Last edited by LuciWiz : 26-Mar-2006 at 10:41. Reason: Please insert your C code between [c] & [/c] tags
  #4  
Old 13-Mar-2005, 17:20
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by WaltP
Without the code it's like talking to your mechanic over the phone trying to describe that weird ping noise and expecting a solution. Be sure to read the sticky post at the top of this forum first.
You must read suggestions.... please
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with simple math table program (was a SIMPLE program) Bubba C Programming Language 3 09-Mar-2005 12:40
Hash Table & Graph Kay Chan C++ Forum 7 08-Oct-2004 07:44
Search data in table. eRIC MySQL / PHP Forum 2 16-May-2004 03:06
customizing preprocessor and hash table incognito54 C Programming Language 2 21-Apr-2004 18:25
[Tutorial] MySQL Basics nniehoff MySQL / PHP Forum 15 23-Mar-2003 19:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:32.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.