fork download
  1. #define NUMMONTHS 12
  2. #define NUMYEARS 5
  3. #include <stdio.h>
  4. #include <string.h>
  5. //function prototypes
  6. void inputdata();
  7. void printdata();
  8.  
  9. // Global variables
  10. // These are available to all functions
  11. float Raindata[NUMYEARS][NUMMONTHS];
  12. char years[NUMYEARS][5] = { "2011","2012","2013","2014","2015" };
  13. char months[NUMMONTHS][12] = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
  14. float sum = 0.0;
  15. float windspeed[59];
  16. int a;
  17. float av = 0;
  18.  
  19. int main()
  20. {
  21. char enterData = 'y';
  22. printf("Do you want to input Precipatation data? (y for yes, n for no)\n");
  23. scanf_s("%c", &enterData);
  24. if (enterData == 'y')
  25.  
  26. {
  27. // Call Function to Input data
  28. inputdata();
  29.  
  30. // Call Function to display data
  31. printdata();
  32. }
  33. else {
  34. printf("No data was input at this time\n");
  35. }
  36. printf("\nPlease try the Precipitation program again. \n");
  37. return 0;
  38. }
  39.  
  40. // function to inputdata
  41. void inputdata() {
  42. /* variable definition: */
  43. float Rain;
  44.  
  45. // Input Data
  46. for (int year = 0; year < NUMYEARS; year++)
  47. {
  48. for (int month = 0; month< NUMMONTHS; month++)
  49. {
  50. Rain = 0.0;
  51. // Input Data rain and wind speed
  52. printf("Enter rainfall inches amount for %s-%s (without symbols) and hit enter.\n", months[month], years[year]);
  53. printf("Rainfall inches: ");
  54. scanf_s("%f", &Rain);
  55. sum = sum + Rain;
  56. av = sum / 5;
  57. Raindata[year][month] = Rain;
  58. printf("Enter windspeed mph for %s-%s\n", months[month], years[year]);
  59. printf("Windspeed mph: \n");
  60. scanf_s("\n%f", &windspeed[a]);
  61. a++;
  62. }
  63. }
  64. }
  65. // Function to printdata
  66. void printdata()
  67. {
  68. // Print data
  69. printf("\nMonth\t Year\t Rain\t Windspeed\n");
  70. int b = 0;
  71.  
  72. for (int month = 0; month< NUMMONTHS; month++)
  73. {
  74. for (int year = 0; year < NUMYEARS; year++)
  75. {
  76. while (b < 60, Raindata[year][month]!=0.00)
  77. {
  78. printf("%s\t %s\t %5.2f\t %5.2f\n", months[month], years[year], Raindata[year][month], windspeed[b]);
  79. b++;
  80. break;
  81. }
  82. }
  83. }
  84. // Print total and average rain fall inches per year
  85. printf("\nTotal RainFall: %5.2f\n", sum);
  86. printf("Average Rainfall inches per year: %5.2f\n", av);
  87. }
  88.  
  89.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:23:1: warning: implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration]
 scanf_s("%c", &enterData);
 ^~~~~~~
prog.c: In function ‘printdata’:
prog.c:76:22: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         while (b < 60, Raindata[year][month]!=0.00)
                      ^
/home/DtpgVL/ccRYG5Tp.o: In function `inputdata':
prog.c:(.text+0x7b): undefined reference to `scanf_s'
prog.c:(.text+0xe7): undefined reference to `scanf_s'
/home/DtpgVL/ccRYG5Tp.o: In function `main':
prog.c:(.text.startup+0x24): undefined reference to `scanf_s'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty