Thread: Cant figure out what is wrong with the programme

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    12

    Cant figure out what is wrong with the programme

    insert
    Code:
    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.

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Dude, don't double post and write in the code tag.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Quote Originally Posted by nimitzhunter View Post
    Dude, don't double post and write in the code tag.
    The reason I had to double post was because I did not know what I was doing wrong.
    I am kind of new for this forum (as a matter of fact I opened my account just yesterday). When somebody said "not to write in the code tag" I did not really know what that meant. But, I think now I know what it means. So anyway this time hopefully I am doing it right. Here is the code for my failed programme:

    insert
    Code:
    #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, 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".

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    There are like three or four copies of the same code in there. I have no clue which file is the error is in. But the mistakes that stand out the most is this in the dailywhatever function
    Code:
     <<setw(16)fStation[K].Temperature <<
    should be
    Code:
     <<setw(16)<<fStation[K].Temperature <<
    "All that we see or seem
    Is but a dream within a dream." - Poe

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Quote Originally Posted by nimitzhunter View Post
    There are like three or four copies of the same code in there. I have no clue which file is the error is in. But the mistakes that stand out the most is this in the dailywhatever function
    Code:
     <<setw(16)fStation[K].Temperature <<
    should be
    Code:
     <<setw(16)<<fStation[K].Temperature <<
    First sorry for posting too many copies of the same programme last time. I am not sure how did that happen.
    Also, thanks for pointing out the mistake and actually that was the only error in the programme. Now my programme is running fine. But, the only problem now I have is that while running the programme after I finish entering the temperature for designated weather station, it executes the function "Menu" twice. To make it more clear, after the programme calls the function "PostWeather", it calls the function "Menu' twice as opposed to once.
    Anyway this time I am making sure that I will post just one copy of the programme. Here comes the code:

    insert
    Code:
    /* 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
      */
                    
    
    
    
    #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;
    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;
    }

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    First of all, fix the indentation so people can actually read your code.

  7. #7
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    The program was also segfaulting when running High-Low Report after entering 12, 18, 11, 6, 27 for the temperatures, because when finding the maximum temperature, when it saw 27 as the largest, it would execute maximum = K + 1; instead of maximum = K; . The segfault occured further down because of:

    Code:
    185     cout << "As for the informaion, the weatherstation" << setw(1)
    186          << fStation[maximum].StationDesignation << setw(3) << " has highest temperature." << endl;
    As to your question about why the menu was printing twice, the problem was that when posting temperatures, you were doing "cin >> Temperature", which is fine, but it doesn't take the newline ('\n') character out of the stream, so when getline is called afterwards in the main loop, the program sees an empty line and Command is set to "". To fix this, I added cin.ignore(256, '\n') to the end of PostWeather().

  8. #8
    Registered User
    Join Date
    Jan 2011
    Posts
    87
    dont you need a space in this?
    Code:
    #include<vector>
    just asking, some simple errors can cause big problems.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A space is not required in there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What am I doing wrong ?
    By scottjge in forum C Programming
    Replies: 6
    Last Post: 10-01-2009, 11:55 AM
  2. Recursive maze, so close, but something is wrong
    By forensicgeek in forum C Programming
    Replies: 9
    Last Post: 09-16-2009, 10:48 PM
  3. Help! I cannot figure out what I'm doing wrong here!
    By chsindian595 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 03:18 AM
  4. Can't figure out what's wrong with Function's Arguments
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2006, 10:30 AM
  5. please help, i can't figure out what's wrong
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2002, 09:13 PM