Yeah, unfortunately I was given 'fire and forget' type of material and I was given a fill in the blank exercise. I work 50 hours a week and nights so it's hard to get help, forums are the best way if at all possible.
I've been playing with it this morning and this is where I am not now...
Code:
#include <stdio.h>
#define NUMMONTHS 12
#define NUMYEARS 5
// function prototypes
void inputdata();
void printdata();
// Global variables
// These are available to all functions
float Raindata[NUMYEARS][NUMMONTHS];
int sum = 0;
int avgsum = 0;
char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int main ()
{
char enterData = 'y';
printf("Do you want to input Precipatation data? (y for yes)\n");
scanf("%c",&enterData);
if (enterData == 'y') {
// Call Function to Input data
inputdata();
// Call Function to display data
printdata();
}
else {
printf("No data was input at this time\n");
}
printf("Please try the Precipitation program again. \n");
return 0;
}
// function to inputdata
void inputdata() {
/* variable definition */
float Rain=1.0;
// Input Data
for (int year=0;year < NUMYEARS; year++) {
for (int month=0; month< NUMMONTHS; month++) {
printf("Enter rain for %d, %d:\n", year+1, month+1);
scanf("%f",&Rain);
Raindata[year][month]=Rain;
}
}
}
// Function to printdata
void printdata()
{
// Print data
sum = 0;
printf ("year\t month\t rain\n");
for (int year=0;year < NUMYEARS; year++)
{
for (int month=0; month < NUMMONTHS; month++)
{
sum += Raindata[year][month];
printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
}
}
printf("Total rain of all five years combined: %d\n", sum);
printf("Average sum of each individual year: %d\n", avgsum);
}
So now I have the sum of all the months functioning properly... how can I get the individual sum for each individual month 1-5?