insertCode:It has been almost straight 6 hours since I have been working on this porgramme. But, I still can't figure out what is wrong with it. Below is the complete code for th programme. Also, any help will be greatly appreciated. /* Title: WeatherReport.cpp Description: This program converts the temperature in Fahrenheit degree into Celsius degree, calculate the average temperature in Fahrenheit for different locations, and determines the lowest and hightest temperaturefor the given day Programmer: Prakash Basnet */ #include <iostream> #include <string> #include<vector> #include <iomanip> using namespace std; struct WeatherStation { double Temperature; // Gives the measurement for the temperature in different units string StationDesignation; // Identify the station }; //All the functions that are going to be used throught the programme void Menu(); void HighLowReport(vector <WeatherStation>&, vector <WeatherStation>&); void DailyReport(vector <WeatherStation>& fStation, vector <WeatherStation>& cStation); void PostWeather(vector<WeatherStation>& fStation, vector< WeatherStation>& cStation); int main() { vector <WeatherStation> fStation(5); // corresponds to the temperature in Fahrenheit vector <WeatherStation> cStation(5); // corresponds to the temperature in Celsius string Command; //Distinguishing different weather stations fStation[0].StationDesignation = "Big Basin"; fStation[1].StationDesignation = "Foothill"; fStation[2].StationDesignation = "DeAnza"; fStation[3].StationDesignation = "MiddleField"; fStation[4].StationDesignation = "Redwood City"; while(true) { Menu(); getline(cin, Command); if(Command == "Quit") break; else if(Command == "Post Temperatures") PostWeather(fStation, cStation); else if(Command == "Daily Report") DailyReport(fStation, cStation); else if(Command == "High-Low Report") HighLowReport(fStation, cStation); } return 0; } void Menu() { cout << " Your command has to be exactly same as any of the 4 options below " << endl; //Incase people enter the wrong command cout << endl; cout << "Post Temperatures" << endl; cout << "Daily Report" << endl; cout << "High-Low Report" << endl; cout << "Quit" << endl; } //Allowing users to enter the temperature data collected from different weather stations void PostWeather(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation) { int K = 0; double Temperature; cout << "Please enter the temperatures in Fahrenheit for designated weather stations" << endl; cout << endl; for(K = 0; K < 5; K++) { cout << "Weather Station " << fStation[K].StationDesignation << ": "; cin >> Temperature; fStation[K].Temperature = Temperature; cStation[K].Temperature = (5 *(Temperature - 32))/9; // Conversion from Fahrenheit into Celsius } } //Displaying of a weather report showing temperature for each weather station and the average temperature void DailyReport(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation) { double fTotal = 0; double cTotal = 0; int K = 0; cout<< fixed <<setprecision(2); cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<<setfill ('=')<< setw(11)<<"=" <<"NGS Temperature data report"<<setfill ('=')<< setw(11)<<"=" << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<< setw(35)<< "Fahrenheit"<< setw(15)<< "Celsisus"<<endl; for(K = 0; K < 5; K++) { cout << "Weather Station " <<setw(4)<< fStation[K].StationDesignation << ": " <<setw(16)fStation[K].Temperature << "\t" <<setw(16)<< cStation[K].Temperature <<endl; fTotal += fStation[K].Temperature; cTotal += cStation[K].Temperature; } cout << "Mean: " <<setw(16)<< fTotal/5 << "\t" << setw(16)<<cTotal/5 << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; } // Determines the highest temperature and the lowest temperature both in fahrenheit and celsius for the given day void HighLowReport(vector<WeatherStation>& fStation, vector <WeatherStation>& cStation) { int K = 0; double highestF = fStation[0].Temperature; double lowestF = fStation[0].Temperature; double highestC = cStation[0].Temperature; double lowestC = cStation[0].Temperature; int maximum = 1; for (K = 0; K < 5; K++) { if(fStation[K].Temperature > highestF) { highestF = fStation[K].Temperature; maximum = K + 1; // determines which station has highest temperature // although not a part of the project, I decided to go little bit further // and determine which stations have the lowest and the highest temperatures. } } int minimum = 1; for (K = 1; K < 5; K++) { if(fStation[K].Temperature < lowestF) { lowestF = fStation[K].Temperature; minimum = K +1 ; //determines which station has lowest temperature } } for (K = 1; K < 5; K++) { if(cStation[K].Temperature > highestC) highestC = cStation[K].Temperature; } for (K = 1; K < 5; K++) { if(cStation[K].Temperature < lowestC) lowestC = cStation[K].Temperature; } cout<< fixed <<setprecision(2); cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<<setfill ('=')<< setw(11)<<"=" <<"NGS Temperature data report"<<setfill ('=')<< setw(11)<<"=" << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<< setw(35)<< "Fahrenheit"<< setw(15)<< "Celsisus"<<endl; cout<< "Lowest Temperature" << setw(12) << lowestF << setw(17) << lowestC << endl; cout<< "Highest Temperature" << setw(11) << highestF << setw(17) << highestC << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout << "As for the informaion, the weatherstation" << setw(1)<< fStation[maximum].StationDesignation << setw(3)<< " has highest temperature." << endl; cout << "Whereas, the weatherstation" << setw(1) << fStation[minimum].StationDesignation <<" has lowest temperature."<<endl; } So, now when I try to compile it, it says that /* Title: WeatherReport.cpp Description: This program converts the temperature in Fahrenheit degree into Celsius degree, calculate the average temperature in Fahrenheit for different locations, and determines the lowest and hightest temperaturefor the given day Programmer: Prakash Basnet */ #include <iostream> #include <string> #include<vector> #include <iomanip> using namespace std; struct WeatherStation { double Temperature; // Gives the measurement for the temperature in different units string StationDesignation; // Identify the station }; //All the functions that are going to be used throught the programme void Menu(); void HighLowReport(vector <WeatherStation>&, vector <WeatherStation>&); void DailyReport(vector <WeatherStation>& fStation, vector <WeatherStation>& cStation); void PostWeather(vector<WeatherStation>& fStation, vector< WeatherStation>& cStation); int main() { vector <WeatherStation> fStation(5); // corresponds to the temperature in Fahrenheit vector <WeatherStation> cStation(5); // corresponds to the temperature in Celsius string Command; //Distinguishing different weather stations fStation[0].StationDesignation = "Big Basin"; fStation[1].StationDesignation = "Foothill"; fStation[2].StationDesignation = "DeAnza"; fStation[3].StationDesignation = "MiddleField"; fStation[4].StationDesignation = "Redwood City"; while(true) { Menu(); getline(cin, Command); if(Command == "Quit") break; else if(Command == "Post Temperatures") PostWeather(fStation, cStation); else if(Command == "Daily Report") DailyReport(fStation, cStation); else if(Command == "High-Low Report") HighLowReport(fStation, cStation); } return 0; } void Menu() { cout << " Your command has to be exactly same as any of the 4 options below " << endl; //Incase people enter the wrong command cout << endl; cout << "Post Temperatures" << endl; cout << "Daily Report" << endl; cout << "High-Low Report" << endl; cout << "Quit" << endl; } //Allowing users to enter the temperature data collected from different weather stations void PostWeather(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation) { int K = 0; double Temperature; cout << "Please enter the temperatures in Fahrenheit for designated weather stations" << endl; cout << endl; for(K = 0; K < 5; K++) { cout << "Weather Station " << fStation[K].StationDesignation << ": "; cin >> Temperature; fStation[K].Temperature = Temperature; cStation[K].Temperature = (5 *(Temperature - 32))/9; // Conversion from Fahrenheit into Celsius } } //Displaying of a weather report showing temperature for each weather station and the average temperature void DailyReport(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation) { double fTotal = 0; double cTotal = 0; int K = 0; cout<< fixed <<setprecision(2); cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<<setfill ('=')<< setw(11)<<"=" <<"NGS Temperature data report"<<setfill ('=')<< setw(11)<<"=" << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<< setw(35)<< "Fahrenheit"<< setw(15)<< "Celsisus"<<endl; for(K = 0; K < 5; K++) { cout << "Weather Station " <<setw(4)<< fStation[K].StationDesignation << ": " <<setw(16)fStation[K].Temperature << "\t" <<setw(16)<< cStation[K].Temperature <<endl; fTotal += fStation[K].Temperature; cTotal += cStation[K].Temperature; } cout << "Mean: " <<setw(16)<< fTotal/5 << "\t" << setw(16)<<cTotal/5 << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; } // Determines the highest temperature and the lowest temperature both in fahrenheit and celsius for the given day void HighLowReport(vector<WeatherStation>& fStation, vector <WeatherStation>& cStation) { int K = 0; double highestF = fStation[0].Temperature; double lowestF = fStation[0].Temperature; double highestC = cStation[0].Temperature; double lowestC = cStation[0].Temperature; int maximum = 1; for (K = 0; K < 5; K++) { if(fStation[K].Temperature > highestF) { highestF = fStation[K].Temperature; maximum = K + 1; // determines which station has highest temperature // although not a part of the project, I decided to go little bit further // and determine which stations have the lowest and the highest temperatures. } } int minimum = 1; for (K = 1; K < 5; K++) { if(fStation[K].Temperature < lowestF) { lowestF = fStation[K].Temperature; minimum = K +1 ; //determines which station has lowest temperature } } for (K = 1; K < 5; K++) { if(cStation[K].Temperature > highestC) highestC = cStation[K].Temperature; } for (K = 1; K < 5; K++) { if(cStation[K].Temperature < lowestC) lowestC = cStation[K].Temperature; } cout<< fixed <<setprecision(2); cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<<setfill ('=')<< setw(11)<<"=" <<"NGS Temperature data report"<<setfill ('=')<< setw(11)<<"=" << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout<< setw(35)<< "Fahrenheit"<< setw(15)<< "Celsisus"<<endl; cout<< "Lowest Temperature" << setw(12) << lowestF << setw(17) << lowestC << endl; cout<< "Highest Temperature" << setw(11) << highestF << setw(17) << highestC << endl; cout<< setfill ('-')<<setw(30)<< "-"<<endl; cout << "As for the informaion, the weatherstation" << setw(1)<< fStation[maximum].StationDesignation << setw(3)<< " has highest temperature." << endl; cout << "Whereas, the weatherstation" << setw(1) << fStation[minimum].StationDesignation <<" has lowest temperature."<<endl; } Note: So, now when I try to compile it , it says that " In function `void DailyReport (std::vector<WeatherStation, std::allocator<WeatherStation> >&, std::vector<WeatherStation, std::allocator<WeatherStation> >&)': expected `;' before "fStation" ". So, I think the problem is in the function "Daily Report". To make it more clear, the compiler shows the error is in the second line of the For Loop I used in the function "Daily Report". Thank You.



LinkBack URL
About LinkBacks



