Exforsys
+ Reply to Thread
Results 1 to 1 of 1

Rainfall.cpp Help

This is a discussion on Rainfall.cpp Help within the C and C++ forums, part of the Programming Talk category; // ************************************************************************** // // Rainfall.cpp // // Reads in the average rainfall for each month (Jan-Dec) and the actual rainfall ...

  1. #1
    n12063 is offline Junior Member Array
    Join Date
    Apr 2011
    Answers
    2

    Rainfall.cpp Help

    // **************************************************************************
    //
    // Rainfall.cpp
    //
    // Reads in the average rainfall for each month (Jan-Dec) and the actual rainfall for each of the previous 12 months (starting date specified by the user) and prints a table indicating whether each month is above or below the average.
    //
    // **************************************************************************
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    void printMonth(int month);
    // PRECONDITION: month holds an integer 1-12
    // POSTCONDITION: the corresponding month (Jan, Feb, ..., Dec) has been
    // printed to the standard output.
    
    int main()
    {
        double rainfall[12];  //this year's rainfall for each month
        double averages[12];  //average rainfalls for each month
        int currentMonth;     //what month is it? 1-based
    
        //
        // Get the average rainfall for each month, Jan-Dec
        // 
    
        cout << "Please enter average rainfall for each month" << endl;
        for (int i=0; i<12; i++)
        {
            printMonth(i);
            cout << ": ";
            cin >> averages[i];
        }
    
        //
        // Get the actual rainfall for the previous year; first have to ask
        // what month it is to know what month to start with.
        // 
    
        cout << "What is the number of the current month?  Jan=1, Feb=2, etc." 
             << endl;
        cin >> currentMonth;
    
        cout << "Please enter the rainfall for each month in the previous year" 
             << endl;
        int count = 0;
        for (int month=currentMonth-1; count < 12; month=(month+1)%12, count++)
        {
            printMonth(month);
            cout << ": ";
            cin >> rainfall[month];
        }
    
        //
        // Print table showing avgs, actual rainfalls, and deviations from avg for previous 12 months.
        // 
    {  
        cout<<setw(20)<<"stuff<<setw(15)<<"Hi";  //will set the width of "stuff" to 20 characters  
    
                                                //and the width of "Hi" to 15 characters  
        
        return 0;  
     } 
    
    
    
    
        // --------------------------------
        // ----- ENTER YOUR CODE HERE -----
        // --------------------------------
    
    
        // --------------------------------
        // --------- END USER CODE --------
        // --------------------------------
    
    }
    
    void printMonth(int month)
    {
        cout.width(8);
        switch(month)
          {
          case 0: 
            cout << "Jan";
            break;
          case 1:
            cout << "Feb";
            break;
          case 2:
            cout << "March";
            break;
          case 3:
            cout << "April";
            break;
          case 4:
            cout << "May";
            break;
          case 5:
            cout << "June";
            break;
          case 6:
            cout << "July";
            break;
          case 7:
            cout << "Aug";
            break;
          case 8:
            cout << "Sept";
            break;
          case 9:
            cout << "Oct";
            break;
          case 10:
            cout << "Nov";
            break;
          case 11:
            cout << "Dec";
            break;
          }
    }


    Last edited by admin; 05-12-2011 at 10:15 AM.

Latest Article

Network Security Risk Assessment and Measurement

Read More...