Else printfno data was input at this timen

Info icon This preview shows pages 34–38. Sign up to view the full content.

else { printf("No data was input at this time\n"); } printf("Please try the Precipitation program again. \n"); return 0; }
Image of page 34

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

// 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; 4 } } } // Function to printdata void printdata(){ // Print data printf ("year\t month\t rain\n"); for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]); } } } Every thing is correct in your code. you change the NUMMONTHES and NUMYEARS definitions to other value then you have to give the value to array in below code. #define NUMMONTHS 6 #define NUMYEARS 6 #include <stdio.h> // function prototypes void inputdata(); void printdata(); // Global variables // These are available to all functions float Raindata[NUMYEARS][NUMMONTHS]; char years[NUMYEARS][5] = { "2011", "2012","2013","2014","2015","2016" }; char months[NUMMONTHS][12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun"}; 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");
Image of page 35
   }    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    printf("year\t month\t rain\n");    for (int year = 0; year < NUMYEARS; year++) {        for (int month = 0; month< NUMMONTHS; month++) {            printf("%s\t %s\t %5.2f\n", years[year], months[month], Raindata[year][month]);        }    } } output:-
Image of page 36

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

1. // C code 2. // This program will input, store, and compute sum of meteorological data into an array. 3. // Developer: Faculty CMIS102 4. // Date: Jan 31, XXXX 5. #define NUMMONTHS 3 6. #define NUMYEARS 2 7. #include <stdio.h> 8. 9. // Function prototypes 10. void inputdata () ; 11. void sumdata () ; 12. float sumAllData () ; 13. void printdata () ; 14.
Image of page 37
Image of page 38
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '09
  • Rain, scanf, enter, windspeed

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern