Hello all!!

Im a newbie when it comes to C++ and I am constructing a program that,
a. reads a file called weatherdata.txt, that contains the type of weather, number of years, then the average data for the months(i did three years)
b.The program displays the informations for the months in the form of asterisks(the values have been multiplied by 10 to get an accurate reading
c. I am supposed to get the average of the first two years as historical, then the last years average as the current average.
d. Then I am supposed to ask the user if they would like to change a value and which one
e. Lastly I reload the file

This is what I have so far,

#include<iostream> 
#include<fstream>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;



	const int NUMBER_OF_MONTHS = 12;

	void calculate_historical(int number_of_years);
	void calculate_current(int number_of_years);
	void get_total_average(double,double,string);
	void graph();
	void print_asterisks(double data_for_months, int numAsterisks);
	void change_Value(double data_for_months, int number_of_years,double newvalue);
	void reload_file();

	double Totals[12];
	double num1;
	double newvalue;

	string climphen;
	int number_of_years(0);
	double data_for_months(0);

	string months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
	ifstream readWeather; 


    int main ()
   {
   
      readWeather.open("weatherdata.txt");
  
      		if (readWeather.fail())
      			{
        				 cout << "Im Sorry, there was an error when attempting to open file. \n";
         			 exit (1); 
      			}
   
      
		string climphen;
      int number_of_years(0);
      int data_for_months(0);
      readWeather>>climphen;
      readWeather>>number_of_years;
		readWeather>>data_for_months;
   
      			cout<<"This program displays and calculates the historical and current data for the amount of ";
      			cout<<climphen<<" for "<<number_of_years<<" years.\r\n"<<"\n";
   
      calculate_historical(number_of_years);
      calculate_current(data_for_months);
   //   get_total_average(Totals[12] , data_for_months, climphen);
  		change_Value(data_for_months,number_of_years,newvalue);		
		 
      readWeather.close();
   
  
      return 0;
  
   }






/******************************************/

    void calculate_historical(int number_of_years)
   {
      	double Totals[12];
      	double num1;
   	
   		   for (int i=1; i<=12;i++)
     				Totals[i]=0;
   		
      		for (int i=0;i<number_of_years -1;i++)
      	{
       			  for (int j=0;j<12;j++)
          		{
       		     		readWeather>>num1;
         	   		cout << months[j]<<", Historical average  = ";
          			
					  int numAsterisks = (int)(num1*10);
					  for (int j=0; j<numAsterisks; j++)
			 			{
							cout <<"*";
		   	 		}
			 				cout<<endl;
			 		}
			}  	 	
         
   }
  

    void calculate_current(int data_for_months)
   {
		
   	   double Totals[12];
    	   double num1;
   	
      		for (int i=1; i<=12;i++)
        			 Totals[i]=0;
   		
    			  for (int j=0;j<12;j++)
      		{
        				readWeather>>num1;
         			cout << months[j]<<", Current average  = ";
			
						int numAsterisks = (int)(num1*10);
						for (int j=0; j<numAsterisks; j++)
					{
							cout <<"*";
					}
		 				cout<<endl;
				}
   	
   }                                          

    
/*	 void get_total_average(double Totals, double data_for_months, string climphen)
   {	
	
			for (int i=0;i<number_of_years -1;i++)
      	{
       			  for (int j=0;j<12;j++)
          		{
       		     		readWeather>>num1;
							
		
      cout<<"\n The total average of the Historical data for "<< climphen <<" is\n"; 
		  
		  
		      
      cout<<"\n The total average of the Current data for "<< climphen <<" is \n";
    
    
   }
	*/
		
	void change_Value(double data_for_months, int number_of_years, double newvalue)
{
	
		 			cout<<"Which value would you like to change?\r\n";
					cout<<"If you do not wish to change any values, please select Q for Quit \r\n";
					cout<<"Plese enter the value you would like to change\n";
						cin>>data_for_months;
			if (data_for_months == 'Q' || 'q')
				{
					cout<<"Thank you, Have a Great Day\n";
						exit(1);
	 			}	
					cout<<"What is the new value?\r\n";
						cin>>newvalue;

				
}

	
	
//void reload_file()

My Problem is getting the average, editing the data, and reloading it. I dont know how to do it. If anyone can help me out I would greatly appreciate it.

calculate_current has an indexing problem.

//      		for (int i=1; i<=12;i++)
       		for (int i=0; i<12;i++)
       			 Totals[i]=0;

Add comments to your code so it makes more sense!

loop j is correct though!

The following isn't doing what you think it does:

//    if (data_for_months == 'Q' || 'q')

       if (data_for_months == 'Q' || data_for_months == 'q')
               pick one of these!
     if (toupper( data_for_months ) == 'Q')

your leave app check should be in the mainline, not in a input data function.

calculate_current has an indexing problem.

//      		for (int i=1; i<=12;i++)
       		for (int i=0; i<12;i++)
       			 Totals[i]=0;

Add comments to your code so it makes more sense!

loop j is correct though!

The following isn't doing what you think it does:

//    if (data_for_months == 'Q' || 'q')

       if (data_for_months == 'Q' || data_for_months == 'q')
               pick one of these!
     if (toupper( data_for_months ) == 'Q')

your leave app check should be in the mainline, not in a input data function.

Thank you,
Yeah I know the last bit of code doesnt do what it should, I have just been expierementing with the code trying to get some sort of out put. But thank you for your reply and your input!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.