Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. int main()
  2. {
  3.  
  4. int yearloop;
  5. double totalrainfall = 0;
  6.  
  7.  
  8. cout << "This program determines how much rainfall fell over a period of time and the average." << endl;
  9. cout << "Please enter the number of years: ";
  10. cin >> yearloop;
  11.  
  12. if (yearloop < 1)
  13. {
  14. cout << "That is not a valid number! Please enter a value of 1 or higher: ";
  15. cin >> yearloop;
  16. }
  17.  
  18. for (int years = 1; years <= yearloop; years++)
  19. {
  20. for (int months = 1; months <= 12; months++)
  21. {
  22. cout << "How many inches of rain fell in year " << years << " month " << months << ": ";
  23. double rainfall;
  24. cin >> rainfall;
  25. if (rainfall < 0)
  26. {
  27. cout << "That isn't a valid number, please enter a positive number: ";
  28. cin >> rainfall;
  29. }
  30. totalrainfall += rainfall;
  31. }
  32.  
  33. }
  34.  
  35. int totalmonths = (yearloop * 12);
  36. cout << "The total amount of months: " << totalmonths << "." << endl;
  37. cout << "The total amount of rainfall: " << totalrainfall << " inches." << endl;
  38. double averageRainfall = totalrainfall / totalmonths;
  39. cout << setprecision(2) << fixed;
  40. cout << "The average rainfall is: " << averageRainfall << " inches per month." << endl;
  41.  
  42. system("pause");
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment