fork(33) download
  1. // C code
  2. // This program will input and store meteorological data into an array.
  3.  
  4. #define NUMMONTHS 12
  5. #define NUMYEARS 5
  6. #include <stdio.h>
  7. // function prototypes
  8. void inputdata();
  9. void printdata();
  10. // Global variables
  11. // These are available to all functions
  12.  
  13.  
  14. float Raindata[NUMYEARS][NUMMONTHS];
  15. char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
  16. char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; int main ()
  17. {
  18. char enterData = 'y';
  19. printf("Do you want to input Precipatation data? (y for yes)\n"); scanf("%c",&enterData);
  20. if (enterData == 'y') {
  21. // Call Function to Input data
  22. inputdata();
  23. // Call Function to display data
  24. printdata();
  25. }
  26. else {
  27. printf("No data was input at this time\n");
  28. }
  29. printf("Please try the Precipitation program again. \n"); return 0;
  30. }
  31.  
  32. // function to inputdata
  33. void inputdata() {
  34. /* variable definition: */
  35. float Rain=1.0;
  36. // Input Data
  37. for (int year=0;year < NUMYEARS; year++) {
  38. for (int month=0; month< NUMMONTHS; month++) { printf("Enter rain for %d, %d:\n", year+1, month+1); scanf("%f",&Rain);
  39. Raindata[year][month]=Rain;
  40. 3;
  41. }
  42. }
  43. }
  44.  
  45. // Function to printdata
  46. void printdata(){
  47. // Print data
  48. printf ("year\t month\t rain\n");
  49. for (int year=0;year < NUMYEARS; year++) {
  50. for (int month=0; month< NUMMONTHS; month++) { printf("%s\t %s\t %5.2f\n",
  51. years[year],months[month],Raindata[year][month]);}
  52. }
  53. }
  54. //Function to sum rainfall
  55. for (int year=0; year< NUMYEARS; year++) {
  56. for (int month=0; month< NUMMONTHS; month++) {
  57. printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
  58. Raindata[year][NUMMONTHS+1] += Raindata[year][month]; //this adds everything up
  59. }
  60. printf("Total amount of rain for year %s: %5.2f\n", years[year], Raindata[year][NUMMONTHS+1]); //prints the total amount of rain every year
  61. }
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
Compilation error #stdin compilation error #stdout 0s 2164KB
stdin
Standard input is empty
compilation info
prog.c: In function 'inputdata':
prog.c:40:1: warning: statement with no effect [-Wunused-value]
 3;
 ^
prog.c: At top level:
prog.c:55:1: error: expected identifier or '(' before 'for'
 for (int year=0; year< NUMYEARS; year++) {
 ^
prog.c:55:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
 for (int year=0; year< NUMYEARS; year++) {
                      ^
prog.c:55:38: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
 for (int year=0; year< NUMYEARS; year++) {
                                      ^
prog.c:62:1: error: expected identifier or '(' before '}' token
 }
 ^
stdout
Standard output is empty