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. double large; // stores largest and smallest values assigned to the array
  16. double small;
  17. double totalRain;
  18. string months[size];
  19.  
  20. cout << "Enter the total rainfall for the first month of the year: " << endl;
  21. cin >> year[0];
  22.  
  23. large = year[0];
  24. small = year[0];
  25. totalRain = year[0];
  26.  
  27. for (int count = 1; count < size; count++)
  28. {
  29. cout << "Enter the total rainfall for month " << count + 1 << endl;
  30. cin >> year[count];
  31.  
  32. while (year[count] < 0) // denies input if negative until a valid number is entered
  33. {
  34. cout << "You cannot enter a negative number. Re-enter number: " << endl;
  35. cin >> year[count];
  36. }
  37.  
  38. totalRain += year[count];
  39.  
  40. if (year[count] > large) // updates the smallest and largest number of the array
  41. large = year[count];
  42. if (year[count] < small)
  43. small = year[count];
  44. }
  45.  
  46. cout << "The rainiest month of the year is month " << large << endl;
  47. cout << "The smallest number in the array is " << small << endl;
  48. cout << "The total rainfall for the whole year is " << totalRain
  49. << " Inches" << endl;
  50.  
  51. return 0;
  52. }
  53.  
  54.  
Success #stdin #stdout 0s 5320KB
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 month 0
The smallest number in the array is 0
The total rainfall for the whole year is 0 Inches