Can't figure out what is wrong with the programme

This is a discussion on Can't figure out what is wrong with the programme within the C++ Programming forums, part of the General Programming Boards category; insert Code: This programme is basically driving me crazy. I have been working on it straight for 9 hours. Here ...

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

    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.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    it also says that `"vector' was not declared in this scope"
    One thing is you need to declare the vector.h header
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Oh! thank you so much for pointing it out. I can't believe I did not think about it. But, now I have declared the vector.h header, there seems to be another problem. Now, it says that " in function int main (), 'class std::vector<WeatherStation, std::allocator<WeatherStation> >' has no member named 'StationDesignation". I have no idea what that means.
    To make it more clear, the compiler now shows problem in the part containing:

    fStation[0].StationDesignation = "Big Basin";
    fStation[1].StationDesignation = "Foothill";
    fStation[2].StationDesignation = "DeAnza";
    fStation[3].StationDesignation = "MiddleField";
    fStation[4].StationDesignation = "Redwood City";

    Need more help. Please.......

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    should be
    Code:
    vector <WeatherStation> fStation(5,WeatherStation_constructor_call() );
    your code means that fStation is an array of 5 vector<WeatherStation>. thus the error.
    Last edited by nimitzhunter; 02-18-2011 at 03:50 AM.
    "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
    should be
    Code:
    vector <WeatherStation> fStation(5,WeatherStation_constructor_call() );
    you say that fStation is an array of 5 vector<WeatherStation>. thus the error.
    Thank you so much for pointing out the mistake. But, there still seems to be a problem. Now when I try to compile it it says " [Linker error] undefined reference to `Menu()' " and " ld returned 1 exit status ". I don't really see what is wrong with my function Menu(). More help will be greatly appreciated.

  6. #6
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    hmmm.... Menu() has never been defined in the file. If it's written somewhere else, then link with that file. Otherwise, you forgot to write the Menu() function.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Quote Originally Posted by nimitzhunter View Post
    hmmm.... Menu() has never been defined in the file. If it's written somewhere else, then link with that file. Otherwise, you forgot to write the Menu() function.
    You were right. So, what happened was I did define the function "menu" but I just gave it a wrong name; instead of calling it "menu", I called it "choices". I really don't know what was I thinking. Anyway, my programme is finally working. And, thank you so much again for your help.

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

    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

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    Please remove your actual message from inside the code tags and indent the code properly.
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21