Can't figure out what is wrong with the programme
insert
Code:
This programme is basically driving me crazy. I have been working on it straight for 9 hours. Here is the code that I have so far written for the programme:
#include <iostream>
#include <string>
using namespace std;
struct WeatherStation {
double Temperature;
string StationDesignation;
};
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];
vector <WeatherStation> cStation[5];
string Command;
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 Choices()
{
cout << "Choose command by typing exactly as shown" << endl;
cout << endl;
cout << "Post Temperatures" << endl;
cout << "Daily Report" << endl;
cout << "High-Low Report" << endl;
cout << "Quit" << endl;
}
void PostWeather(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation)
{
int K = 0;
double Temperature;
cout << "Please enter the Fahrenheit temperatures" << 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;
}
}
void DailyReport(vector<WeatherStation>& fStation, vector<WeatherStation>& cStation)
{
double fTotal = 0;
double cTotal = 0;
int K = 0;
cout << "NGS Daily Temperature Report" << endl;
for(K = 0; K < 5; K++)
{
cout << "Weather Station " << fStation[K].StationDesignation << ": " << fStation[K].Temperature << "\t" << cStation[K].Temperature << endl;
fTotal += fStation[K].Temperature;
cTotal += cStation[K].Temperature;
}
cout << "Mean: " << fTotal/5 << "\t" << cTotal/5 << endl;
}
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;
for (K = 0; K < 5; K++)
{
if(fStation[K].Temperature > highestF)
highestF = fStation[K].Temperature;
}
for (K = 0; K < 5; K++)
{
if(fStation[K].Temperature < lowestF)
lowestF = fStation[K].Temperature;
}
for (K = 0; K < 5; K++)
{
if(cStation[K].Temperature > highestC)
highestC = cStation[K].Temperature;
}
for (K = 0; K < 5; K++)
{
if(cStation[K].Temperature < lowestC)
highestC = cStation[K].Temperature;
}
cout << "Lowest: " << lowestF << "\t" << lowestC << endl;
cout << "Highest: " << highestF << "\t" << highestC << endl;
}
But, whenever I try to compile it, it says " variable or field `HighLowReport' declared void" it also says that `"vector' was not declared in this scope". Actually it says variable or field declared void for all of my functions. I just can't figure out the problem. Any help will be greatly appreciated.
Programme not working again!
insert
Code:
So, to give programme a good format, I made some changes. But, those changes were just supposed to make the programme look nice and clear and not meant to affect the operation of the programme. However, my programme is not running anymore. Here is the complete code for the programme:
/* 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;
}
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".
Any help will be greatly appreciated