fork download
  1. #define NUMMONTHS 12
  2. #define NUMYEARS 5
  3. #include <stdio.h>
  4.  
  5. // function prototypes
  6. void inputdata();
  7. void printdata();
  8. // Global variables
  9. // These are available to all functions
  10. float Raindata[NUMYEARS][NUMMONTHS];
  11. char months[NUMMONTHS][12]
  12. ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  13. int main (){
  14.  
  15. char enterData = 'y';
  16. printf("Do you want to input Precipatation data? (y for yes)\n");
  17. scanf("%c",&enterData);
  18. if (enterData == 'y') {
  19. // Call Function to Input data
  20. inputdata();
  21. // Call Function to display data
  22. // printdata();
  23. }
  24. else{
  25. printf("No data was input at this time\n");
  26. }
  27. printf("Please try the Precipitation program again. \n");
  28. return 0;
  29. }
  30. // function to inputdata
  31. void inputdata() {
  32. /* variable definition: */
  33. float Rain=1.0;
  34. // Input Data
  35. int arr[5], i, num;
  36. printf("\nHow many years:");
  37. scanf("%d", &num);
  38. printf("%d", num);
  39. for (i = 0; i < num; i++) {
  40. scanf("%d + 1 ", &arr[i]);
  41. }
  42. for (int year=0;year < num; year++) {
  43. for (int month=0; month< NUMMONTHS; month++) {
  44. scanf("%f",&Rain);
  45. Raindata[year][month]=Rain;
  46. }
  47. }
  48. //}
  49. // Function to printdata
  50. // Print data
  51. printf ("\nyear\t month\t rain\n");
  52. //for (i = 0; i < num; i++)
  53. //for (int year=0;year < num; year++)
  54. for (int month=0; month< NUMMONTHS; month++)
  55. printf("\%d\t %s\t %5.2f\n",
  56. arr[i],months[month],Raindata[year][month]);
  57. }
Compilation error #stdin compilation error #stdout 0s 9432KB
stdin
y
5
2011
1.2
2.2
3.3
2.2
10.2
12.2
2.3
0.4
0.2
1.1
2.1
0.4
1.1
2.2
3.3
2.2
10.2
12.2
2.3
0.4
0.2
1.1
2.1
0.4
1.1
2.2
3.3
2.2
10.2
12.2
2.3
0.4
0.2
1.1
2.1
0.4
1.1
2.2
3.3
2.2
10.2
12.2
2.3
0.4
0.2
1.1
2.1
0.4
1.1
2.2
3.3
2.2
10.2
12.2
2.3
0.4
0.2
1.1
2.1
0.4
compilation info
prog.c: In function ‘inputdata’:
prog.c:56:33: error: ‘year’ undeclared (first use in this function)
   arr[i],months[month],Raindata[year][month]);
                                 ^~~~
prog.c:56:33: note: each undeclared identifier is reported only once for each function it appears in
stdout
Standard output is empty