Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int yearloop;
- double totalrainfall = 0;
- cout << "This program determines how much rainfall fell over a period of time and the average." << endl;
- cout << "Please enter the number of years: ";
- cin >> yearloop;
- if (yearloop < 1)
- {
- cout << "That is not a valid number! Please enter a value of 1 or higher: ";
- cin >> yearloop;
- }
- for (int years = 1; years <= yearloop; years++)
- {
- for (int months = 1; months <= 12; months++)
- {
- cout << "How many inches of rain fell in year " << years << " month " << months << ": ";
- double rainfall;
- cin >> rainfall;
- if (rainfall < 0)
- {
- cout << "That isn't a valid number, please enter a positive number: ";
- cin >> rainfall;
- }
- totalrainfall += rainfall;
- }
- }
- int totalmonths = (yearloop * 12);
- cout << "The total amount of months: " << totalmonths << "." << endl;
- cout << "The total amount of rainfall: " << totalrainfall << " inches." << endl;
- double averageRainfall = totalrainfall / totalmonths;
- cout << setprecision(2) << fixed;
- cout << "The average rainfall is: " << averageRainfall << " inches per month." << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment