I'm currently in an introduction to programming course and my current assignment is using functions. I thought I had a good grasp, but alas I am for once in this course completely stuck. I do not have the time to ask my professor for help (the assignment is due tomorrow) so any advice or suggestions would be completely appreciated.

This is the code I have so far :

#include <stdio.h> #include <stdlib.h> #define SIZE 5 double getValidRainfall(){ double result; printf("\n Enter a rainfall amount: "); scanf("%lf", &result); while (result < 0.0) { printf("%.2lf is not a valid rainfall amount.", result); printf("\n Enter another rainfall amount: "); scanf("%lf", &result); } return result; } double calculateTotal(double rainfall[], int size){ double result = 0.0; int i; for(i = 0; i < size; i++){ result += rainfall [i]; } return result; } double findLargest(double rainfall[], int size){ double result = 0.0; int i; for(i = 0; i < size; i++){ if(rainfall[i] > result) result = rainfall[i]; } return result; } double findSmallest(double rainfall [], int size){ double result = 0.0; int i; for(i = 0; i < size; i++){ if(rainfall[i] < result) result = rainfall[i]; } return result; } double calculateResults(){ double rainfall[SIZE], totalRainfall, averageRainfall, smallestRainfall; double largestRainfall, result = 0.0; totalRainfall = calculateTotal( rainfall, SIZE ); averageRainfall = totalRainfall / SIZE; largestRainfall = findLargest(rainfall, SIZE); smallestRainfall = findSmallest(rainfall, SIZE); return result; } double displayOutput(){ double rainfall[SIZE], totalRainfall, averageRainfall, smallestRainfall; double largestRainfall, result; calculateResults(); printf("The total rainfall is %.2lf\n", totalRainfall); printf("The average daily rainfall is %.2lf\n", averageRainfall); printf("The largest daily rainfall is %.1lf\n", largestRainfall); printf("The smallest daily rainfall is %.1lf\n", smallestRainfall); return result; } main(){ double rainfall[SIZE], totalRainfall, averageRainfall, smallestRainfall; double largestRainfall; int i; for( i = 0; i < SIZE; i++) rainfall[i] = getValidRainfall(); displayOutput(); system("pause"); }

No matter what I try to do the variables won't initialize correctly. I need a function to display the output. Could someone explain to me how to go about this or give me advice? I recognize there are probably far better ways to write this program, but I am stuck with the assignment being what it is. Thank you in advance.

This post has been edited by **jimblumberg**: 20 April 2013 - 08:08 AM

Reason for edit:: Fixed Code Tags.