Rainfall Calculator in C++

Mar 22, 2015 12:39 · 243 words · 2 minute read C++

Project: Write a program that prompts the user to input seven values – each value represents the number of inches of rainfall on a particular day of the week. (Note: The values may be whole units such as 2 or 5 or fractional values such as 2.5 or 1.33. Make sure you chose an appropriate data type to handle either type of data.) Based on the input, calculate the total rainfall and average rainfall for the seven days period. Output the total and average in decimal form.

#include <iostream>
using namespace std;

int main() {
    // Declare variables
    //
    double day1, day2, day3, day4, day5, day6, day7, total, average;

    // User input
    //
    cout << "Enter the rain fall over the past 7 days." << endl
        << "Day 1: ";
    cin >> day1;
    cout << "Day 2: ";
    cin >> day2;
    cout << "Day 3: ";
    cin >> day3;
    cout << "Day 4: ";
    cin >> day4;
    cout << "Day 5: ";
    cin >> day5;
    cout << "Day 6: ";
    cin >> day6;
    cout << "Day 7: ";
    cin >> day7;

    // Calculate Total and Average
    //
    total = (day1 + day2 + day3 + day4 + day5 + day6 + day7);
    average = (total / 7);

    cout << "The total rainfall for the past 7 days was: " << total << endl;
    cout << "The average rainfall for the past 7 days was: " << average << endl;


    system("pause");
    return 0;
}