0

I need help in order to make the code work

///
///
///
///
///
/// Program: Weather data processing
/// Created by: Wesley Montgomery
/// This program anlizes weather data accessed from a file and finds the average of Temperature, Humidity, and other facts.
///
///
///

#include <fstream>	
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>  // for min() and max()
#include <sstream>
#include <iomanip>


using namespace std;
void read_file(
  ifstream& file,        // The open and ready-to-read csv data file
  string    targetdate,  // The date we are interested in (see note below)
  int       temp, // The index of the field we are interested in
  int       pressure, // The index of the field we are interested in
  int       humidity, // The index of the field we are interested in
  double&   temp_min,         // Where to put the minimum of the indexed field
  double&   temp_max,        // Where to put the maximum
  double&   pres_min,         // Where to put the minimum of the indexed field
  double&   pres_max,        // Where to put the maximum
  double&   humi_min,         // Where to put the minimum of the indexed field
  double&   humi_max        // Where to put the maximum
);
void read_filewindmax( 
  ifstream& file,        // The open and ready-to-read csv data file 
  string    targetdate,  // The date we are interested in (see note below) 
  int       wind, // The index of the field we are interested in 
  double&   wind_max        // Where to put the maximum 
);


void get_dates( ifstream& file, string dates[], int& size );

int main()
{ 
	int pressure, temp, windspeed, humidity, rainfall, min_temp, max_temp, min_pres, max_pres, min_humi, max_humi, wind_max;
	bool  done; // exit flag 
	char  selection; //Menu Selection
	string file; // Name of datafile
	ifstream weatherfile; //datafile stream


	// Initialize exit flag
	 done = false;

	while (!done) 
	{
		// Output menu list
		cout << "\n\n";
		cout << "************************\n\n";		
		cout << "  Weather Data Analysis: \n";		
		cout << "  1) Select Data File to be loaded\n";		
		cout << "  2) Daily Min/max of Temp,Pressure and humidity\n";		
		cout << "  3) Daily Max Wind Speed\n";		
		cout << "  4) Avg Pressure, Humidity, and Windspeed for rainy days\n";	
		cout << "  5) \n";
		cout << "  6) Exit Program\n";
		cout << "************************\n\n";		

		// Input data					
		cout << "Selection -> ";		
		cin >> selection;
		cout << "\n\n";

		// Process input
		if (selection=='1') 
		{
			cout << "Insert Data file:";
			cin >> file; 
			weatherfile.open (file.c_str(), ios::in);
			cout << "\n\n";
		}
		else if (selection=='2')
		{
			while (!weatherfile.eof())
			{
				string targetdate = "04/18/2008"; // whatever the target day is
              read_file( weatherfile, targetdate, temp, pressure, humidity, min_temp, max_temp, min_humi, max_humi, min_pres, max_pres);
              cout << targetdate << ": ";
              cout << "The Minimum Temperature is" << setw(10) << setprecision(2) << min_temp << "degrees." << endl;
              cout << "The Maximum Temperature is" << setw(10) << setprecision(2) << max_temp << "degrees." << endl;
			  cout << "The Minimum Pressure is" << setw(10) << setprecision(2) << min_pres << "millibars." << endl;
              cout << "The Maximum Pressure is" << setw(10) << setprecision(2) << max_pres << "millibars." << endl;
			  cout << "The Minimum Humidity is" << setw(10) << setprecision(2) << min_humi << endl;
              cout << "The Maximum Humidity is" << setw(10) << setprecision(2) << max_humi << endl;
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		
		else if (selection=='3')
		{
			while (!weatherfile.eof())
			{
				string targetdate = "04/18/2008"; // whatever the target day is
              read_filewindmax(weatherfile, targetdate, windspeed, wind_max);
              cout << targetdate << ": ";
              cout << "The Maximum Wind Speed is" << setw(10) << setprecision(2) << wind_max << "miles per hour." << endl;
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='4')
		{
			while (!weatherfile.eof())
			{
			if (rainfall > 0)
			{ 

			}
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='5')
		{
			while (!weatherfile.eof())
			{

				
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='6')
		{
			cout << "Goodbye. Thank you for using my program.\n\n";
			done = true;					// flag for exit
		}
		else
		{
			cout << "** Invalid Selection. **\n\n";
		}
		weatherfile.close();

	} // end of while loop

	return (0);
}

the Same errors occur as last time. I really need help with this code.

0

These variables are integers:

int pressure, temp, windspeed, humidity, rainfall, min_temp, max_temp, min_pres, max_pres, min_humi, max_humi, wind_max;

Here is your function call:

read_file( weatherfile, targetdate, temp, pressure, humidity, min_temp, max_temp, min_humi, max_humi, min_pres, max_pres);

Here is your function declaration:

void read_file(
  ifstream& file,        // The open and ready-to-read csv data file
  string    targetdate,  // The date we are interested in (see note below)
  int       temp, // The index of the field we are interested in
  int       pressure, // The index of the field we are interested in
  int       humidity, // The index of the field we are interested in
  double&   temp_min,         // Where to put the minimum of the indexed field
  double&   temp_max,        // Where to put the maximum
  double&   pres_min,         // Where to put the minimum of the indexed field
  double&   pres_max,        // Where to put the maximum
  double&   humi_min,         // Where to put the minimum of the indexed field
  double&   humi_max        // Where to put the maximum
);

It is expecting you to pass it doubles for the last six variables.
See red variable highlighting. You are passing integers to a function that expects doubles. Decide whether the function should take doubles or integers. If it should take doubles, declare the variables as doubles. If it should take integers, change the function so it takes integers, not doubles. They need to match.

0

Ok I did what you said but now I'm getting a LNK1120 error

///
///
///
///
///
/// Program: Weather data processing
/// Created by: Wesley Montgomery
/// This program anlizes weather data accessed from a file and finds the average of Temperature, Humidity, and other facts.
///
///
///

#include <fstream>	
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>  // for min() and max()
#include <sstream>
#include <iomanip>


using namespace std;
void read_file(
  ifstream& file,        // The open and ready-to-read csv data file
  string    targetdate,  // The date we are interested in (see note below)
  int       temp, // The index of the field we are interested in
  int       pressure, // The index of the field we are interested in
  int       humidity, // The index of the field we are interested in
  int temp_min,         // Where to put the minimum of the indexed field
  int temp_max,        // Where to put the maximum
  int pres_min,         // Where to put the minimum of the indexed field
  int pres_max,        // Where to put the maximum
  int humi_min,         // Where to put the minimum of the indexed field
 int  humi_max        // Where to put the maximum
);
void read_filewindmax( 
  ifstream& file,        // The open and ready-to-read csv data file 
  string    targetdate,  // The date we are interested in (see note below) 
  int       wind, // The index of the field we are interested in 
  int   wind_max        // Where to put the maximum 
);


void get_dates( ifstream& file, string dates[], int& size );

int main()
{ 
	int  rainfall, temp, pressure, humidity, windspeed, wind_max, min_temp, max_temp, min_humi, max_humi, min_pres, max_pres ;
	bool  done; // exit flag 
	char  selection; //Menu Selection
	string file; // Name of datafile
	ifstream weatherfile; //datafile stream


	// Initialize exit flag
	 done = false;

	while (!done) 
	{
		// Output menu list
		cout << "\n\n";
		cout << "************************\n\n";		
		cout << "  Weather Data Analysis: \n";		
		cout << "  1) Select Data File to be loaded\n";		
		cout << "  2) Daily Min/max of Temp,Pressure and humidity\n";		
		cout << "  3) Daily Max Wind Speed\n";		
		cout << "  4) Avg Pressure, Humidity, and Windspeed for rainy days\n";	
		cout << "  5) \n";
		cout << "  6) Exit Program\n";
		cout << "************************\n\n";		

		// Input data					
		cout << "Selection -> ";		
		cin >> selection;
		cout << "\n\n";

		// Process input
		if (selection=='1') 
		{
			cout << "Insert Data file:";
			cin >> file; 
			weatherfile.open (file.c_str(), ios::in);
			cout << "\n\n";
		}
		else if (selection=='2')
		{
			while (!weatherfile.eof())
			{
				string targetdate = "04/18/2008"; // whatever the target day is
              read_file( weatherfile, targetdate, temp, pressure, humidity, min_temp, max_temp, min_humi, max_humi, min_pres, max_pres);
              cout << targetdate << ": ";
              cout << "The Minimum Temperature is" << setw(10) << setprecision(2) << min_temp << "degrees." << endl;
              cout << "The Maximum Temperature is" << setw(10) << setprecision(2) << max_temp << "degrees." << endl;
			  cout << "The Minimum Pressure is" << setw(10) << setprecision(2) << min_pres << "millibars." << endl;
              cout << "The Maximum Pressure is" << setw(10) << setprecision(2) << max_pres << "millibars." << endl;
			  cout << "The Minimum Humidity is" << setw(10) << setprecision(2) << min_humi << endl;
              cout << "The Maximum Humidity is" << setw(10) << setprecision(2) << max_humi << endl;
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		
		else if (selection=='3')
		{
			while (!weatherfile.eof())
			{
				string targetdate = "04/18/2008"; // whatever the target day is
              read_filewindmax(weatherfile, targetdate, windspeed, wind_max);
              cout << targetdate << ": ";
              cout << "The Maximum Wind Speed is" << setw(10) << setprecision(2) << wind_max << "miles per hour." << endl;
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='4')
		{
			while (!weatherfile.eof())
			{
			if (rainfall > 0)
			{ 

			}
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='5')
		{
			while (!weatherfile.eof())
			{

				
			}
			weatherfile.clear();
            weatherfile.seekg( 0 );
		}
		else if (selection=='6')
		{
			cout << "Goodbye. Thank you for using my program.\n\n";
			done = true;					// flag for exit
		}
		else
		{
			cout << "** Invalid Selection. **\n\n";
		}
		weatherfile.close();

	} // end of while loop

	return (0);
}

Anything you see wrong?

0

Ok I did what you said but now I'm getting a LNK1120 error


Anything you see wrong?

Read my earlier posts. That's the linker error I was referring to. You haven't written the function yet, so you can't call it.

0

Ok I'm going to be honest, I have no idea what the heck I'm doing. I don't know how to fix this and I need help to do this program.

0
read_file( weatherfile, targetdate, temp, pressure, humidity, min_temp, max_temp, min_humi, max_humi, min_pres, max_pres);

the function is not defined...you declared it but there is nothing in it..hence when you call there is nothing to call

0

Stick this at the end of your program:

void read_file( ifstream& file, string targetdate, int temp, int  pressure, int humidity, int temp_min, int temp_max, int pres_min, int pres_max, int humi_min, int humi_max)
{
     // put function code here
}

See if that compiles. It won't do what you want it to when you run it, but see if that gets it to compile. Also go back to Duoas's post 17 when he originally suggested this function. Notice the & in his code. You've taken them out. You need to put them back in. You want to pass these variables by reference.

0

It seems like you are having some trouble with functions.

You might want to take a look through the Functions I and II parts of this C++ Language Tutorial on cplusplus.com. It is very complete and easy to read. You'll need to understand this stuff to finish your assignment with top grade.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.