Thread: Basic function functioning

  1. #1
    Registered User
    Join Date
    Aug 2009

    Basic function functioning


    This should work, only its dosent. would anyone be kind enough to gently point me in the right direction? It tells me that array is undeclared in "void judge" if thats worth anything. heres the code

    #include <stdio.h>
    #include <conio.h>
    void judge(int Array[]);
    void count(int Array[], int *total);
    int sum;
    int array[5]={0};
    printf("Points are being counted\n\n");
    count(array, &sum);
    printf("%d", sum);
    void judge(int Array[])
    int i;
    for(i=1; i<5; i++){
             printf("Give %d. judges points\n", i+1);
             scanf("%d", &array[i]);
    void count(int Array[], int *total)
          for(i=1; i<5; i++){

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    First of all, using a hard-coded value to keep track of the array size is error-prone and generally considered bad form. You should pass it as a parameter to the function. As to the error, it's because the variables 'array' and 'sum' are not visible (nor do they exist) within the context of the function. You could of course make them global variables (eg: outside of main) but this also is usually an indication of a bad design. At any rate, you probably meant to use the variables that you passed to the function 'Array' and 'total', correct? Even so, attempting to add the elements of the array to the address of 'sum' doesn't make much sense, either, does it?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    also your sum variable is not initialized, so it contains garbage. Suppose you'll fix the part that adds the elements of the array to the correct total, what it will be if you start with some random value?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

Tags for this Thread