I want to say thank you to everyone in advanced for all the help that has been provided. I am currently stuck on two more items on this program. Currently I am completely stumped on how to create a bar graph using the information gathered by the program. Some reason I can't decipher how the book does it. The second part is how do I get the table and bar graph to print out to a file. Hopefully this isn't a lot that I am asking. Also thanks to Ancient Dragon for help earlier.

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<fstream>

using namespace std;

const int MONTHS = 12;//Constant for number of months.
void getAvg(double avgRain[], string months[]);//Function declaration for getAvg.
void getCurrent(int& month, string months[]);//Function declaration for getCurrent month.
void getAct(double actRain[], double avgRain[], string months[], int& month);//Function declaration for getAct.
void printTable(double avgRain[], double actRain[], string months[]);//Function declaration for printTable.
void printBaravg(double avgRain[], string months[]);//Function declaration for printBaravg.

int main()
{

     double avgRain[MONTHS];//avgRain[] variable
     double actRain[MONTHS];//actRain[] variable
     int month;//month variable
     string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};//String for the month names used in the program.

     getAvg(avgRain, months);//getAvg function call.
     //getCurrent(month, months);//getCurrent function call.
     getAct(actRain, avgRain, months, month);//getAct function call.
     printTable(avgRain, actRain, months);//printTable function call.
     //printBaravg(avgRain, months);//printBaravg function call.

     return 0;
}


void getAvg(double avgRain[], string months[])//getAvg function definition.
{
     ifstream inputFile;//Tells the program where to look for input data file.

     inputFile.open("rainfall_current.dat");//Opens the file rainfall_current file.

     for ( int i = 0; i < 12; i++ )//Counts down the array to insert the information.
     {
          inputFile >> avgRain[i];//Fills the array with information from the file.
          //cout << avgRain[i];//Test
     }

     inputFile.close();//Closes the file.
     
    
     for ( int i = 0; i < MONTHS; i++ )//For loop that counts down the months and the avgRain array to receive data.
      
     cout << months[i] <<" : "//Output statement that prints out the month name.
          << avgRain[i] <<endl;//Output statement that prints the average rainfall numbers.

     return;     
}


void getAct(double actRain[], double avgRain[], string months[], int& month)//Function definition for getAct.
{
     ifstream inputFile;//Tells the program where to look for input data file.

     inputFile.open("rainfall_previous.dat");//Opens the file rainfall_previous file.

     for ( int i = 0; i < 12; i++ )//Counts down the array to insert the information.
     {
          inputFile >> actRain[i];//Fills the array with information from the file.
          //cout << actRain[i];//Test
     }

     inputFile.close();//Closes the file.
    
     cout << endl << endl;
     
    
     for ( int i = 0; i < MONTHS; i++ )//For loop that counts down the months and the actRain array to receive data. 
     
     cout << months[i] <<" : "//Output statement that prints out the month name.
          << actRain[i] << endl;//Output statement that prints the actual rainfall numbers.    
     
     return;
}

void getCurrent(int& month, string months[])//getCurrent function definition.
{
     
     cout << "\nPlease enter the current month. " //Asks the user to input the month using digits between 1 and 12.
          << "Use 1 for January, 2 for February, "
          << "and so on." << endl;
     cin  >> month;//Input for the current month.
    
     if ( month >= 1 && month <= MONTHS )//If loop portion that determines if the number that is entered is between 1 and 12.
	 {
          cout << "\nThe current month is " << months[month - 1] << endl;//Prints out the current month from the input gathered from the user.
	 } 
	 else if ( month < 1 )//If loop portion that determines if the number entered is below 1.
	 {
		  cout << "You must enter a non-negative number between 1 and 12." << endl;//Output that informs the user that they have entered an invalid number.
		  getCurrent(month, months);//Reruns the getCurrent function.
	 }
	 else if ( month > MONTHS )//If loop portion that determines is the number enteres is above 12.
	 {
		  cout << "You must enter a smaller number between 1 and 12." << endl;//Output that informs the user that they have entered an invalid number.
		  getCurrent(month, months);//Reruns the getCurrent function.
     }
     return;
}

void printTable(double avgRain[], double actRain[], string months[])//Function definition for printTable.
{
    double total, total2;//Local variables
    
    ofstream outputFile;
    outputFile.open("rainfall_output.dat");
     

    cout << endl << endl;
    cout << "Month" << setw(18) << " Average" << setw(11) << " Actual" << setw(16) << " Total Below" << setw(13) << " Total Above" << endl;//Header for the output table.
    cout << setw(23) << "Rainfall" << setw(12) << "Rainfall" << setw(13) << " Average" << setw(12) << " Average" << endl << endl;
     for (int i = 0; i < 12; i++)//Counts the month and arrays down allowing the information to be processed.
     {    
          total = avgRain[i] - actRain[i];//Used to gather the below average totals.
          total2 = actRain[i] - avgRain[i];//Used to gather the above average totals.
          //cout << total;//Test for total.
          if( total < 0 )//Used to check if total is <= 0.
          {
              total = 0;//Used to write zero to a position instead of a negative integer.
              //cout << total;//Test
          }
          if ( total2 < 0)//Used to check if total2 is <= 0.
          {
               total2 = 0;//Used to write zero to a position instead of a negative integer.
               //cout << total2;//Test
          }
                   
          
      cout << setw(11) << left << months[i] << setw(11) << right << avgRain[i] << setw(11)
      << actRain[i] << setw(11) << total << setw(15) << total2 << endl;//Prints out the output in a table with the month, average rain, actual rain, above average rain and below average rain.
    
    
    } 
     
     outputFile.close();
}

void printBaravg(double avgRain[], string months[])
{

}

Hint: Write the bar graph out line by line. Draw out a sample by hand and see which values have stars printed on which lines. After you've figured it out using cout, send the output to your ofstream object instead. Give it a try and see how far you can get.

This question has already been answered. Start a new discussion instead.