100% honesty I am stuck on a homework assignment. I need to sum the raindata for each individual year. I am sure my code is overly complicated but so far I have done my best on my own and am starting to get desperate. My code is below. I am sure the multiple if statements and creation of the count variable are unneeded but I dont want the exact easy answer if possible I would like to fix the current code but if I need to scrap the entire function I would rather know now since I am running out of time.
Code:
// C code
// This program will input and store meteorological data into an array.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#define NUMMONTHS 12
#define NUMYEARS 5
#include <stdio.h>
// function prototypes
void inputdata();
void printdata();
void sumdata();
// Global variables
// These are available to all functions
float Raindata[NUMYEARS][NUMMONTHS];
float Winddata[NUMYEARS][NUMMONTHS];
float sum;
int count;
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();
sumdata();
}
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;
float Wind=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);
scanf("%f",&Wind);
Raindata[year][month]=Rain;
Winddata[year][month]=Wind;
}
}
}
// Function to printdata
void printdata()
{
// Print data
printf ("year\t month\t rain\t wind\n");
for (int year=0;year < NUMYEARS; year++) {
for (int month=0; month< NUMMONTHS; month++) {
printf("%s\t %s\t %.2f\t %f\n",
years[year],months[month],Raindata[year][month],Winddata[year][month]);
}
}
}
//Function to sumdata
void sumdata()
{
sum = 0.0;
count = 0;
for (int year=0;year < NUMYEARS; year++) {
for (int month=0; month< NUMMONTHS; month++) {
count = count + 1;
sum = sum + Raindata[year][month];
if (count == 12)
printf("%f\n",sum);
if (count == 24)
printf("%f\n",sum);
if (count == 36)
printf("%f\n",sum);
if (count == 48)
printf("%f\n",sum);
if (count == 60)
printf("%f\n",sum);
}
}
}