fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define NUMMONTHS 12
  6. #define NUMYEARS 5
  7.  
  8. /* globals */
  9. float Raindata[NUMYEARS][NUMMONTHS];
  10. char years[NUMYEARS][5] = { "2011", "2012", "2013", "2014", "2015" };
  11. char months[NUMMONTHS][12] =
  12. { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
  13. "Nov", "Dec" };
  14. float sum = 0.0;
  15. float windspeed[59];
  16. int a;
  17. float av = 0;
  18.  
  19. /* prototypes */
  20. void inputdata ();
  21. void printdata ();
  22.  
  23. int main (void) {
  24.  
  25. char enterData = 'y';
  26. printf ("Do you want to input Precipatation data? (y/n)\n");
  27. if (scanf ("%c%*c", &enterData) != 1) {
  28. fprintf (stderr, "error: invalid input (precip data).\n");
  29. return 1;
  30. }
  31.  
  32. if (enterData == 'y') {
  33. inputdata (); /* call function to input data */
  34. printdata (); /* call function to print data */
  35. }
  36. else
  37. printf ("No data was input at this time\n");
  38.  
  39. printf ("\nPlease try the Precipitation program again. \n");
  40. return 0;
  41. }
  42.  
  43. void inputdata ()
  44. {
  45. float Rain;
  46.  
  47. for (int year = 0; year < NUMYEARS; year++) {
  48. for (int month = 0; month < NUMMONTHS; month++) {
  49. Rain = 0.0;
  50.  
  51. printf ("Enter rainfall inches amount for %s-%s (without symbols)\n",
  52. months[month], years[year]);
  53. printf ("Rainfall inches: ");
  54. if (scanf (" %f", &Rain) != 1) {
  55. fprintf (stderr, "error: invalid input (rainfall).\n");
  56. exit (EXIT_FAILURE);
  57. }
  58. sum = sum + Rain;
  59. av = sum / 5;
  60. Raindata[year][month] = Rain;
  61.  
  62. printf ("Enter windspeed mph for %s-%s\n", months[month],
  63. years[year]);
  64. printf ("Windspeed mph: ");
  65. if (scanf (" %f", &windspeed[a]) != 1) {
  66. fprintf (stderr, "error: invalid input (windspeed).\n");
  67. exit (EXIT_FAILURE);
  68. }
  69. a++;
  70. }
  71. }
  72. }
  73.  
  74. void printdata ()
  75. {
  76. printf ("\nMonth\t Year\t Rain\t Windspeed\n");
  77. int b = 0;
  78.  
  79. for (int month = 0; month < NUMMONTHS; month++) {
  80. for (int year = 0; year < NUMYEARS; year++) {
  81. while (b < 60 && Raindata[year][month] != 0.00) {
  82. printf ("%s\t %s\t %5.2f\t %5.2f\n", months[month],
  83. years[year], Raindata[year][month], windspeed[b]);
  84. b++;
  85. break;
  86. }
  87. }
  88. }
  89.  
  90. printf ("\nTotal RainFall: %5.2f\n", sum);
  91. printf ("Average Rainfall inches per year: %5.2f\n", av);
  92. }
  93.  
Success #stdin #stdout 0s 9432KB
stdin
y
9 12
2 19
5 2
9 17
12 6
11 5
9 4
6 19
2 7
5 9
5 8
6 22
11 19
15 24
3 28
8 11
2 17
6 28
3 22
15 21
4 25
11 28
14 16
8 22
14 4
1 18
3 21
1 29
2 30
14 4
4 21
7 20
7 27
3 17
10 24
7 29
10 24
11 30
1 25
7 6
13 14
15 30
11 15
5 27
6 3
8 25
1 29
14 22
2 23
15 19
8 29
2 18
14 4
2 7
13 30
12 17
5 27
8 1
3 28
4 9
stdout
Do you want to input Precipatation data? (y/n)
Enter rainfall inches amount for Jan-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Jan-2011
Windspeed mph: Enter rainfall inches amount for Feb-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Feb-2011
Windspeed mph: Enter rainfall inches amount for Mar-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Mar-2011
Windspeed mph: Enter rainfall inches amount for Apr-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Apr-2011
Windspeed mph: Enter rainfall inches amount for May-2011 (without symbols)
Rainfall inches: Enter windspeed mph for May-2011
Windspeed mph: Enter rainfall inches amount for Jun-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Jun-2011
Windspeed mph: Enter rainfall inches amount for Jul-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Jul-2011
Windspeed mph: Enter rainfall inches amount for Aug-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Aug-2011
Windspeed mph: Enter rainfall inches amount for Sep-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Sep-2011
Windspeed mph: Enter rainfall inches amount for Oct-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Oct-2011
Windspeed mph: Enter rainfall inches amount for Nov-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Nov-2011
Windspeed mph: Enter rainfall inches amount for Dec-2011 (without symbols)
Rainfall inches: Enter windspeed mph for Dec-2011
Windspeed mph: Enter rainfall inches amount for Jan-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Jan-2012
Windspeed mph: Enter rainfall inches amount for Feb-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Feb-2012
Windspeed mph: Enter rainfall inches amount for Mar-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Mar-2012
Windspeed mph: Enter rainfall inches amount for Apr-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Apr-2012
Windspeed mph: Enter rainfall inches amount for May-2012 (without symbols)
Rainfall inches: Enter windspeed mph for May-2012
Windspeed mph: Enter rainfall inches amount for Jun-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Jun-2012
Windspeed mph: Enter rainfall inches amount for Jul-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Jul-2012
Windspeed mph: Enter rainfall inches amount for Aug-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Aug-2012
Windspeed mph: Enter rainfall inches amount for Sep-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Sep-2012
Windspeed mph: Enter rainfall inches amount for Oct-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Oct-2012
Windspeed mph: Enter rainfall inches amount for Nov-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Nov-2012
Windspeed mph: Enter rainfall inches amount for Dec-2012 (without symbols)
Rainfall inches: Enter windspeed mph for Dec-2012
Windspeed mph: Enter rainfall inches amount for Jan-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Jan-2013
Windspeed mph: Enter rainfall inches amount for Feb-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Feb-2013
Windspeed mph: Enter rainfall inches amount for Mar-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Mar-2013
Windspeed mph: Enter rainfall inches amount for Apr-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Apr-2013
Windspeed mph: Enter rainfall inches amount for May-2013 (without symbols)
Rainfall inches: Enter windspeed mph for May-2013
Windspeed mph: Enter rainfall inches amount for Jun-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Jun-2013
Windspeed mph: Enter rainfall inches amount for Jul-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Jul-2013
Windspeed mph: Enter rainfall inches amount for Aug-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Aug-2013
Windspeed mph: Enter rainfall inches amount for Sep-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Sep-2013
Windspeed mph: Enter rainfall inches amount for Oct-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Oct-2013
Windspeed mph: Enter rainfall inches amount for Nov-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Nov-2013
Windspeed mph: Enter rainfall inches amount for Dec-2013 (without symbols)
Rainfall inches: Enter windspeed mph for Dec-2013
Windspeed mph: Enter rainfall inches amount for Jan-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Jan-2014
Windspeed mph: Enter rainfall inches amount for Feb-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Feb-2014
Windspeed mph: Enter rainfall inches amount for Mar-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Mar-2014
Windspeed mph: Enter rainfall inches amount for Apr-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Apr-2014
Windspeed mph: Enter rainfall inches amount for May-2014 (without symbols)
Rainfall inches: Enter windspeed mph for May-2014
Windspeed mph: Enter rainfall inches amount for Jun-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Jun-2014
Windspeed mph: Enter rainfall inches amount for Jul-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Jul-2014
Windspeed mph: Enter rainfall inches amount for Aug-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Aug-2014
Windspeed mph: Enter rainfall inches amount for Sep-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Sep-2014
Windspeed mph: Enter rainfall inches amount for Oct-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Oct-2014
Windspeed mph: Enter rainfall inches amount for Nov-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Nov-2014
Windspeed mph: Enter rainfall inches amount for Dec-2014 (without symbols)
Rainfall inches: Enter windspeed mph for Dec-2014
Windspeed mph: Enter rainfall inches amount for Jan-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Jan-2015
Windspeed mph: Enter rainfall inches amount for Feb-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Feb-2015
Windspeed mph: Enter rainfall inches amount for Mar-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Mar-2015
Windspeed mph: Enter rainfall inches amount for Apr-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Apr-2015
Windspeed mph: Enter rainfall inches amount for May-2015 (without symbols)
Rainfall inches: Enter windspeed mph for May-2015
Windspeed mph: Enter rainfall inches amount for Jun-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Jun-2015
Windspeed mph: Enter rainfall inches amount for Jul-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Jul-2015
Windspeed mph: Enter rainfall inches amount for Aug-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Aug-2015
Windspeed mph: Enter rainfall inches amount for Sep-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Sep-2015
Windspeed mph: Enter rainfall inches amount for Oct-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Oct-2015
Windspeed mph: Enter rainfall inches amount for Nov-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Nov-2015
Windspeed mph: Enter rainfall inches amount for Dec-2015 (without symbols)
Rainfall inches: Enter windspeed mph for Dec-2015
Windspeed mph: 
Month	 Year	 Rain	 Windspeed
Jan	 2011	  9.00	 12.00
Jan	 2012	 11.00	 19.00
Jan	 2013	 14.00	  2.00
Jan	 2014	 10.00	 17.00
Jan	 2015	  2.00	  6.00
Feb	 2011	  2.00	  5.00
Feb	 2012	 15.00	  4.00
Feb	 2013	  1.00	 19.00
Feb	 2014	 11.00	  7.00
Feb	 2015	 15.00	  9.00
Mar	 2011	  5.00	  8.00
Mar	 2012	  3.00	 22.00
Mar	 2013	  3.00	 19.00
Mar	 2014	  1.00	 24.00
Mar	 2015	  8.00	 28.00
Apr	 2011	  9.00	 11.00
Apr	 2012	  8.00	 17.00
Apr	 2013	  1.00	 28.00
Apr	 2014	  7.00	 22.00
Apr	 2015	  2.00	 21.00
May	 2011	 12.00	 25.00
May	 2012	  2.00	 28.00
May	 2013	  2.00	 16.00
May	 2014	 13.00	 22.00
May	 2015	 14.00	  4.00
Jun	 2011	 11.00	 18.00
Jun	 2012	  6.00	 21.00
Jun	 2013	 14.00	 29.00
Jun	 2014	 15.00	 30.00
Jun	 2015	  2.00	  4.00
Jul	 2011	  9.00	 21.00
Jul	 2012	  3.00	 20.00
Jul	 2013	  4.00	 27.00
Jul	 2014	 11.00	 17.00
Jul	 2015	 13.00	 24.00
Aug	 2011	  6.00	 29.00
Aug	 2012	 15.00	 24.00
Aug	 2013	  7.00	 30.00
Aug	 2014	  5.00	 25.00
Aug	 2015	 12.00	  6.00
Sep	 2011	  2.00	 14.00
Sep	 2012	  4.00	 30.00
Sep	 2013	  7.00	 15.00
Sep	 2014	  6.00	 27.00
Sep	 2015	  5.00	  3.00
Oct	 2011	  5.00	 25.00
Oct	 2012	 11.00	 29.00
Oct	 2013	  3.00	 22.00
Oct	 2014	  8.00	 23.00
Oct	 2015	  8.00	 19.00
Nov	 2011	  5.00	 29.00
Nov	 2012	 14.00	 18.00
Nov	 2013	 10.00	  4.00
Nov	 2014	  1.00	  7.00
Nov	 2015	  3.00	 30.00
Dec	 2011	  6.00	 17.00
Dec	 2012	  8.00	 27.00
Dec	 2013	  7.00	  1.00
Dec	 2014	 14.00	 28.00
Dec	 2015	  4.00	  9.00

Total RainFall: 444.00
Average Rainfall inches per year: 88.80

Please try the Precipitation program again.