Thread: Arrays and Enumerated Data Types

  1. #1
    Registered User
    Join Date
    Dec 2011
    Location
    Princess Anne, Maryland, United States
    Posts
    8

    Arrays and Enumerated Data Types

    I am doing a programming assignment. This program asks you to collect statistics on precipitation and temperatures from the four quarters of a year and print the calculated results. It is an exercise in using enumerated types and arrays. The measurements are entered at the end of every quarter.

    Major variables (there are other variables) in the program:
    Variable called: month of type Summary_Month (the enumerated type)
    Arrays of integers called: low_temp, high_temp, precip
    Array of doubles called: avg_temp

    You will ask the user to enter the precipitation, low temperature and high temperature for each quarter. As you gather this data, you will calculate the average temperature (using avg_temp) for each quarter by averaging the low and high temperature for that quarter.

    After you gather the information you will calculate and output the following:
    Total Precipitation for Year, Average Quarterly Precipitation, Average Quarterly Temperature, Highest Temperature for any quarter, Lowest Temperature for any quarter.

    I am not getting the right output for average precipitation and temperature and I am not sure how to determine the highest and lowest temperature. Any help will be greatly appreciated.

    Code:
    
    
    Code:
    # include <iostream> 
    # include <iomanip> 
    
    
    using namespace std; 
    
    
    enum Quarters { March, June, September, December}; 
    
    
    int main() 
    
    
    {
        const int NUM_QUARTERS = 4; 
        /*double avg_temp [NUM_QUARTERS]; */
        double totalp = 0.0; 
        double avgt = 0.0; 
        double avgp = 0.0; 
     
        int low_temp [4]; 
        int high_temp [4]; 
        int precip [4]; 
    
    
        Quarters monthQuarters; 
    
    
        for (monthQuarters = March; monthQuarters <= December; 
                                    monthQuarters = static_cast<Quarters>(monthQuarters +1))
    
    
        {
            cout << "Enter the precipitation for Quarter " << monthQuarters +1 << endl << endl; 
            cin >> precip[monthQuarters]; 
            cout << endl << endl; 
    
    
            cout << "Enter the low temperature for Quarter " << monthQuarters +1 << endl << endl; 
            cin >> low_temp[monthQuarters]; 
            cout << endl << endl; 
    
    
            cout << "Enter the high temperature for Quarter " << monthQuarters +1 << endl << endl; 
            cin >> high_temp[monthQuarters]; 
            cout << endl << endl; 
    
    
        }
    
    
        for (monthQuarters = March; monthQuarters <= December; 
                                    monthQuarters = static_cast<Quarters>(monthQuarters +1))
    
    
        {
            avgt += (low_temp[monthQuarters] + high_temp[monthQuarters]) / 8; 
            avgp  += (precip[monthQuarters] ) / 4; 
            totalp += precip[monthQuarters]; 
        
            
        }
    
    
            cout << "The Average Temp for the year is " << avgt << endl << endl; 
            cout << "The Average Precipitation for the year is " << avgp << endl << endl; 
            cout << "The Total Percipitation for the year is " << totalp << endl << endl; 
        
    
    
        
    
    
        system ("pause"); 
    
    
        return 0; 
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > avgt += (low_temp[monthQuarters] + high_temp[monthQuarters]) / 8;
    > avgp += (precip[monthQuarters] ) / 4;
    These will be done as integer arithmetic, not as floats.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Another huge ........ing waste of time with a cross-post already answered over here
    Arrays And Enumerated Data Types - C And C++ | Dream.In.Code
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with enumerated data types.
    By And3rs in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2008, 10:06 AM
  2. enumerated types
    By Raison in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2003, 02:59 PM
  3. Replies: 1
    Last Post: 02-06-2003, 03:33 PM
  4. Overloading Enumerated Types?
    By Witch_King in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2001, 04:57 AM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM