[Solved] C++ Need help for a homework program that reads in a list of doubles from a file and add a string to each double


Call bubbleSort(rain, MAX_MONTHS); in main with these changes :

void displayRainfall(string months[MAX_MONTHS], double rain[MAX_MONTHS], int monthCount)
{
    //title
    cout << "Monthly Rainfall for 2014" << endl;

    //print minimum rainfall
    cout << "Minimum: " << months[MAX_MONTHS-1] << " "<< rain[MAX_MONTHS-1] << endl;

    //print maximum rainfall
    cout << "Maximum: " << months[0] << " "<< rain[0] << endl; 

    //get and print average rainfall
    double avg = 0.0;
    for (int i = 0; i < MAX_MONTHS; i++)
    {
        avg+=rain[i];
    }
    avg = avg/MAX_MONTHS;
    cout << "Monthly Average for Year: " << avg << endl;

    //print ordered rainfall by month
    cout << "Sorted by Total Rainfall" << endl;
    cout << "Month" << setw(10) << "Inches" << setw(10) << endl;
    for (int i = 0; i < MAX_MONTHS; i++)
    {
        cout << setw(10) <<months[i] << setw(10) << rain[i] << endl;
    }
}    

void bubbleSort(double rain[MAX_MONTHS], int size)
{
    string months[MAX_MONTHS] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
    //sort rainfall descending
    for (int i = 1; i < size; i++)
    {
        for (int j = 0; j < size - i; j++)
        {
            if (rain[j] < rain[j+1])
            {
                swap(rain[j], rain[j+1]);
                swap(months[j], months[j+1]);
            }
        }
    }
    //called inside bubbleSort because months and rain are sorted in scope
    displayRainfall(months, rain, 0);
}

void swap(int& a, int& b)
{
    int& temp = a;
    a = b;
    b = temp;
}

solved C++ Need help for a homework program that reads in a list of doubles from a file and add a string to each double