fork download
  1. /*******************************************************************************
  2.  * Aiden Stannard // CS1A // Chapter 7 Homework: Challange 1# // 10/30/2026
  3.  *
  4.  * Rainfall Stats
  5.  *
  6.  * This program recieves
  7.  ******************************************************************************/
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. const int size = 12; // Value for the size of the array
  14. double year[size]; // array definition
  15. string months[size] = {"January","February", "March", "April", "May"
  16. "June","July","Augest","September","October","November","December"};
  17. double large;
  18. double small;
  19. string largeMonth;
  20. string smallMonth;
  21. double totalRain;
  22.  
  23. cout << "Enter the total rainfall for the first month of the year: " << endl;
  24. cin >> year[0];
  25.  
  26. totalRain = year[0];
  27. large = year[0];
  28. small = year[0];
  29. largeMonth = months[0];
  30. smallMonth = months[0];
  31.  
  32. for (int count = 1; count < size; count++)
  33. {
  34. cout << "Enter the total rainfall for " << months[count] << endl;
  35. cin >> year[count];
  36.  
  37. while (year[count] < 0) // denies input if negative until a valid number is entered
  38. {
  39. cout << "You cannot enter a negative number. Re-enter number: " << endl;
  40. cin >> year[count];
  41. }
  42.  
  43. totalRain += year[count];
  44.  
  45. if (year[count] > large)
  46. large = year[count];
  47. largeMonth = months[count];
  48. if (year[count] < small)
  49. large = year[count];
  50. smallMonth = months[count];
  51. }
  52.  
  53. cout << "The rainiest month of the year is " << largeMonth << endl;
  54. cout << "The smallest number in the array is " << smallMonth << endl;
  55. cout << "The total rainfall for the whole year is " << totalRain
  56. << " Inches" << endl;
  57. cout << "The Average rainfall monthly rainfall is " << totalRain / size << endl;
  58. return 0;
  59. }
  60.  
  61.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Enter the total rainfall for the first month of the year: 
Enter the total rainfall for month 2
Enter the total rainfall for month 3
Enter the total rainfall for month 4
Enter the total rainfall for month 5
Enter the total rainfall for month 6
Enter the total rainfall for month 7
Enter the total rainfall for month 8
Enter the total rainfall for month 9
Enter the total rainfall for month 10
Enter the total rainfall for month 11
Enter the total rainfall for month 12
The rainiest month of the year is 
The smallest number in the array is 
The total rainfall for the whole year is 0 Inches
The Average rainfall monthly rainfall is 0