CH11_4

http://www.chegg.com/homework-help/questions-and-answers/question-please-help-question-write-program-uses-structure-store-following-weather-data-pa-q3363800

https://www.daniweb.com/software-development/cpp/threads/395877/weather-structure-program




  1. // This program collects the weather statistics for a year. The data it collects is total rainfall, high temp, low temp, average temp.
  2. //Programming Challenge 11.4
  3. #include <iostream>
  4. #include <string>
  5. #include <iomanip>
  6. using namespace std;
  7. struct Weather
  8. {
  9. double rainfall;
  10. double high_temp;
  11. double low_temp;
  12. double avg_temp;
  13. };
  14. // Function Prototypes
  15. /*double getTotalrain(double);
  16. double getAvgrain(double);
  17. double getAverageTemp(double);
  18. double getHighTemp(double);
  19. double getLowTemp(double);*/
  20. int main()
  21. {
  22. const int NUM_MONTHS = 12; //Number of Months
  23. Weather months[NUM_MONTHS]; //Array of 12 months
  24. int index; //Loop counter
  25. double annualRainfall=0.0,averageRainfall;
  26. // Get rainfall for each month.
  27. for (int index = 0; index < NUM_MONTHS; index++)
  28. {
  29. // Get months rainfall
  30. cout << "Enter the rainfall in inches for month #:";
  31. cout << (index + 1) << ": ";
  32. cin >> months[index].rainfall;
  33. cout<<months[index].rainfall;
  34. annualRainfall+=months[index].rainfall;
  35. averageRainfall=annualRainfall/12;
  36. }
  37. // Display total rainfall.
  38. cout << "The total rainfall for the year is ";
  39. cout << annualRainfall
  40. << " inches." << endl;
  41. // Display the average rainfall from the year
  42. cout << "The average rainfall for the year is ";
  43. //float average = months[index].rainfall / 12;
  44. cout << averageRainfall << " inches." << endl;
  45. cin.get();
  46. return 0;

Popular posts from this blog

ch11 review silberschatz operating systems concepts essentials 2nd ed