fork(1) download
  1. #define NUMMONTHS 12
  2. #define NUMYEARS 5
  3. #include <stdio.h>
  4. void inputdata();
  5. void printdata();
  6. void sumdata();
  7. float Raindata[NUMYEARS][NUMMONTHS],sum;
  8. char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
  9. char months[NUMMONTHS][12]
  10. ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  11. int main ()
  12. {
  13.  
  14. char enterData = 'y';
  15. printf("Do you want to input Precipatation data? (y for yes)\n");
  16. scanf("%c",&enterData);
  17. if (enterData == 'y')
  18. {
  19. inputdata();
  20. printdata();
  21. }
  22. if (enterData == 's')
  23. {
  24. sumdata();
  25. }
  26. else {
  27. printf("No data was input at this time\n");
  28. }
  29. printf("Please try the Precipitation program again. \n");
  30. return 0;
  31. }
  32. void inputdata() {
  33. float Rain=1.0;
  34. for (int year=0;year < NUMYEARS; year++) {
  35. for (int month=0; month< NUMMONTHS; month++) {
  36. printf("Enter rain for %d, %d:\n", year+1, month+1);
  37. scanf("%f",&Rain);
  38. Raindata[year][month]=Rain;
  39. }
  40. }
  41. }
  42. void printdata(){
  43. printf ("year\t month\t rain\n");
  44. for (int year=0;year < NUMYEARS; year++) {
  45. for (int month=0; month< NUMMONTHS; month++) {
  46. printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
  47. }
  48. }
  49. }
  50. void sumdata(){
  51. float value, sum;
  52. sum=0;
  53. while(count<12)
  54. {
  55. printf("Enter a rain for month\n");
  56. scanf("%f", &value);
  57. sum = sum = value;
  58. }
  59. printf("sum is %f\n", sum);
  60. if (Rain< 0){
  61.  
  62. return 0;
  63. }
  64. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
s
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
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
2.1
0.4
0.2
1.1
2.1
0.4
1.1
2.2
3.3
2.
10.2
12.2
2.3
0.2
0.2
1.1
2.1
0.4
compilation info
prog.c: In function ‘sumdata’:
prog.c:53:14: error: ‘count’ undeclared (first use in this function)
        while(count<12)
              ^~~~~
prog.c:53:14: note: each undeclared identifier is reported only once for each function it appears in
prog.c:57:13: warning: operation on ‘sum’ may be undefined [-Wsequence-point]
         sum = sum = value;
         ~~~~^~~~~~~~~~~~~
prog.c:60:11: error: ‘Rain’ undeclared (first use in this function)
       if (Rain< 0){
           ^~~~
prog.c:62:17: warning: ‘return’ with a value, in function returning void
          return 0;
                 ^
prog.c:50:13: note: declared here
       void  sumdata(){
             ^~~~~~~
stdout
Standard output is empty