fork download
  1. //Sam Trivikraman CS1A Chapter 11, p. 646, #4
  2. //
  3. /*
  4.  ******************************************************************************
  5. Store Weather Stats
  6. _______________________________________________________________________________
  7. This program stores the total fainfall, highest temperatures, lowest temperatures,
  8. and average temperatures for each month of the year.
  9. _______________________________________________________________________________
  10. INPUT
  11. total rainfall : The total inches of rainfall for the month
  12. highest temperature : The highest temperature for the month
  13. lowest temperature : The lowest temperature for the month
  14. average temperature : The average temperature for the month
  15.  
  16. OUTPUT
  17. array of weather stats : An array that stores all of the details for the weather for the year
  18. _______________________________________________________________________________
  19. *******************************************************************************
  20. */
  21.  
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. //structure that stores the weather stats
  26. struct weather
  27. {
  28. int totalRain; //INPUT The total inches of rainfall for the month
  29. int highTemp; //INPUT The highest temperature for the month
  30. int lowTemp; //INPUT The lowest temperature for the month
  31. int avgTemp; //INPUT The average temperature for the month
  32. };
  33.  
  34. int main() {
  35.  
  36. weather info[12]; //OUTPUT An array that stores all of the details for the weather for the year
  37. int rain; //OUTPUT the total amount of rain for a year
  38. int highest = 0; //OUTPUT the highest temperature for the year
  39. int lowest = 140; //OUTPUT the lowest temperature for the year
  40. int average; //OUTPUT the average temperature for the year
  41.  
  42. //ask the user for the inches of rain per month, highest temp, lowest temp
  43. //calculate the total amount of rain for the year
  44. for(int i = 0; i < 12; i++)
  45. {
  46. cout << "Please enter the total inches of rain" << endl;
  47. cin >> info[i].totalRain;
  48. rain += info[i].totalRain;
  49. cout << "Please enter the highest temperature from this month" << endl;
  50. cin >> info[i].highTemp;
  51.  
  52. if(info[i].highTemp > highest)
  53. {
  54. highest = info[i].highTemp;
  55. }
  56. cout << "Please enter the lowest temperature from this month" << endl;
  57. cin >> info[i].lowTemp;
  58.  
  59. if(info[i].lowTemp < lowest)
  60. {
  61. lowest = info[i].lowTemp;
  62. }
  63.  
  64. }
  65.  
  66. //Output total monthly rainfall, highest and lowest temps
  67. cout << "The total monthly rainfall is: " << rain << " inches." << endl;
  68. cout << "The highest temperature is: " << highest << " degrees." << endl;
  69. cout << "The lowest temperature is: " << lowest << " degrees." << endl;
  70. return 0;
  71. }
Success #stdin #stdout 0.01s 5304KB
stdin
1
2
3
4
5
6
1
2
3
4
5
6
stdout
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
Please enter the total inches of rain
Please enter the highest temperature from this month
Please enter the lowest temperature from this month
The total monthly rainfall is: -1069987926 inches.
The highest temperature is: 21984 degrees.
The lowest temperature is: -1809517991 degrees.