Thread: Need help calling outside of main with arrays

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    4

    Need help calling outside of main with arrays

    Hello,

    Working on a project for school and I am stuck. It is a program to calculate windchill and although I have it working, I need to call outside of the main program to calculate the mean and min_max values, which I have both in the main. Calling outside of the main is my weak-point for sure, and really need help help here. Don't mind the location of my declarations and stuff I will clean that up after I got this working how it should, haha.

    Basically, we need to use function prototypes:

    1.) double mean(double[], int)

    2.) void min_max(double [], int)

    And this is my program:

    Code:
    #include <stdio.h>
    #include <math.h>
    #define INFO "data_5a_08.txt"
    #define N 10
    void info (void);
    
    
    int main ()
    {
    //declarations
    info ();
    int T[N], V[N];
    double windchill[N], mean=0, sum =0, max = 0, min = 0;
    int k = 0;
    
    //file open
    FILE*data;
    data = fopen(INFO, "r");
    
    if (data == NULL)
    printf("Error opening file\n\n");
    
    else
    	{
    		printf("Temp (F):	Wind Speed (mph):     Wind Chill:\n");
    		for (int k=0; k<=N-1; k++)
    		{
    			while((fscanf(data,"%i %i", &T[k], &V[k])) == 1);
    			windchill[k] = 35.74 + 0.6215*T[k] - 35.75*pow(V[k],0.16)+ 0.4275*T[k]*pow(V[k],0.16);
    			printf("%3i \t\t %3i \t\t %13.1lf\n", T[k], V[k], windchill[k]);
    		}
    		
    		//mean
    		for (int z=0; z<=N-1; z++)
    		{
    			sum = sum + windchill[z];
    			mean = sum;
    		}
    		printf("\n\nAverage Windchill:%5.1f\n\n", mean/N);
    
    		//min and max chills
    		for (int y=0; y<=N-1; y++)
    			{
    				if(windchill[y]>max)
    					max= windchill[y];
    				else if (windchill[y]<min)
    					min= windchill[y];
    			}
    		printf("Max Windchill:%5.1f\n\n", max);
    		printf("Min Windchill:%5.1f\n\n", min);
    		fclose(data);
    	}
    return 0;
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://www.cprogramming.com/tutorial/lesson4.html

    The above shows some function basics, albeit in C++. It's very similar for C.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having some trouble calling a function in the main program
    By CMakesMeSad :( in forum C Programming
    Replies: 19
    Last Post: 06-26-2009, 09:33 PM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 01:48 PM
  4. calling a function inside main()
    By mero24 in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2005, 01:22 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM