Thread: can't figue out what is wrong with the programme

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    can't figue out what is wrong with the programme


    I just could not figure out what is wrong with this programmed. I have tried as much as I could to make it work. But, it does not seem to be working. So, I would greatly appreciate it if anybody could give me some help to make this programme work. Anyway here is the code for the programme:


    Code:
    
            #include <iostream>
            #include <string> 
            #include <vector>
            #include <fstream>
            
            using namespace std;
            
            
            class PollenAirQuality
            {
            public:
            PollenAirQuality() {PollenCount= AirIndex= 0; }
            void SetPollenCount(double Count) { PollenCount = Count; }
            double GetPollenCount() { return PollenCount;
            void SetAirIndex(double Index) { AirIndex = Index; }
            double GetAirIndex() {return AirIndex; }
            
            protected:
            double PollenCount;
            double AirIndex;
            
            };
            
          
            
            class WeatherStation : public PollenAirQuality
            {
            public:
            WeatherStation();
            
            void SetDesignation(string ID) { StationDesignation = ID; }
            void SetAgent(string Agent) { StationAgent = Agent; }
            void SetTemperature(double Degree) { Temperature = Degree; }
            
            double Convert(double DegreeF);
            
            string GetDesignation() { return StationDesignation; }
            string GetAgent() { return StationAgent; }
            double GetTemperature() { return Temperature; }
            
            protected:
            string StationDesignation;
            string StationAgent; 
            double Temperature; 
            
            };
            
            WeatherStation::WeatherStation()
            {
            StationDesignation = "";
            StationAgent = "";
            Temperature = 0;
            }
            
            double WeatherStation::Convert(double degreeF)
            {
            double degreeC;
            
            // convert Fahrenheit to Celcius
            degreeC = ((degreeF - 32) * 5) / 9;
            
            return degreeC;
            }
            
            class VectorList
            {
            vector<WeatherStation> List;
            vector<WeatherStation>::iterator ILister;
            
            string FileName;
            
            public:
            VectorList() { FileName = "Temp"; }
            VectorList(string FName) { FileName = FName; }
            
            void AddStations();
            void PostStationInfo();
            void DailyReport();
            void HighLowReport();
            void PollenCount();
            void AirQualityIndex();
            double GetMaxF();
            double GetMinF();
            double GetAvgF();
            
            void SetFileName(string FName) { FileName = FName; }
            void WriteToFile();
            void ReadFromFile();
            
            };
            
            void VectorList::AddStations()
            {
            WeatherStation Station;
            string Designation, Agent;
            
            cout << "Enter Station Information Below, Stop To Quit\n";
            
            for (;;)
            {
            cout << "\n-------------------------------\n";
            
            cout << "Enter Weather Station Designation: ";
            getline (cin, Designation);
            if (Designation == "Stop")
            break;
            Station.SetDesignation( Designation );
            
            cout << "\nEnter Contact Person: ";
            getline (cin, Agent);
            if (Agent == "Stop")
            break;
            Station.SetAgent( Agent );
            
            cout << "\n-------------------------------\n";
            
            List.push_back(Station);
            
            }
            }
            void VectorList::PostStationInfo()
            { 
            double Degree, Count, Index;
            
            cout << "Enter reported temperatures: (in Fahrenheit) \n\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\n";
            cout << ILister->GetAgent();
            
            cout << "\nEnter Temperature:\t";
            cin >> Degree;
            ILister->SetTemperature( Degree );
            
            cout << "\n\tPollen Count:\t";
            cin >> Count;
            ILister->SetPollenCount( Count );
                           
            cout << "\n\tAir Quality Index:\t";
            cin >> Index;
            ILister->SetAirIndex( Index );
            
            cin.ignore(100, '\n');
            }
            }
            
            void VectorList::DailyReport()
            {
            cout << " NGS Daily Temperature Report \n";
            cout << "===========================================================\n";
            cout << "\t\t Fahrenheit(°F) \t Celsius (°C)";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << "\n-----------------------------------------------------------\n";
            cout << (*ILister).GetDesignation() << "\t\t ";
            cout << (*ILister).GetTemperature() << "\t\t\t" 
            << (*ILister).Convert( (*ILister).GetTemperature() );
            }
            
            cout << "\n-----------------------------------------------------------";
            cout << "\nMean Temperature: \t " << GetAvgF() // The first problem is here
            << "\t\t\t" << (*ILister).Convert(GetAvgF() );
            cout << "\n===========================================================\n\n";
            }
            
            void VectorList::HighLowReport()
            {
            cout << " NGS High-Low Report ";
            cout << "\n==========================================================";
            cout << "\n\t\t Fahrenheit(°F) \t Celsius (°C)";
            cout << "\n----------------------------------------------------------";
            cout << "\nLowest Temperature:\t " << GetMinF() //Second problem
            << "\t\t\t" << (*ILister).Convert( GetMinF() );
            cout << "\n----------------------------------------------------------";
            cout << "\nHighest Temperature:\t " << GetMaxF() //Third problem
            << "\t\t\t" << (*ILister).Convert( GetMaxF() );
            cout << "\n----------------------------------------------------------";
            cout << "\n==========================================================\n";
            }
            
            
            void VectorList::PollenCount()
            {
            
            cout << " NGS Daily Pollen Report\n";
            cout << "==================================\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\t\t" << ILister->GetPollenCount() << "\n";
            }
            cout << "==================================\n\n";
            }
            
            void VectorList:: AirQualityIndex()
            {
            cout << " NGS Air Quality Index  Report\n";
            cout << "==================================\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\t\t" << ILister->GetAirIndex() << "\n";
            }
            cout << "==================================\n\n";
            }
            
            double VectorList::GetMaxF()
            {
            double maxF;
            
            maxF = ILister->GetTemperature();
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            // find the highest temperture in Fahrenheit
            if ( (*ILister).GetTemperature() > maxF)
            maxF = (*ILister).GetTemperature();
            }
            return maxF;
            }
            double VectorList::GetMinF()
            {
            double minF;
            
            minF = ILister->GetTemperature();
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            // find the lowest temperture in Fahrenheit
            if ( (*ILister).GetTemperature() > minF)
            minF = (*ILister).GetTemperature();
            }
            return minF;
            }
            
            
            double VectorList::GetAvgF()
            {
            double Total = 0, Mean;
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            Total += ILister->GetTemperature();
            
            Mean = Total / List.size();
            
            return Mean;
            }
            void VectorList::WriteToFile() 
            {
            fstream OutFile(FileName.c_str(), ios::out);
            
            for ( ILister = List.begin(); ILister < List.end(); ILister++)
            {
            OutFile << ILister->GetDesignation() << endl;
            OutFile << ILister->GetAgent() << endl;
            OutFile << ILister->GetTemperature() << endl;
            OutFile << ILister->GetPollenCount() << endl;
            OutFile << ILister->GetAirIndex() << endl;
            }
            
            OutFile.close();
            }
            
            void VectorList::ReadFromFile()
            {
            fstream InFile(FileName.c_str(), ios::in);
            
            string Designation, Agent;
            double Temperature, Count, Index;
            WeatherStation Temp;
            
            while(true)
            {
            getline(InFile, Designation); 
            getline(InFile, Agent);
            InFile >> Temperature;
            InFile >> Count;
            InFile >> Index;
            
            InFile.ignore(100, '\n'); 
            
            if(InFile.eof())
            break;
            
            Temp.SetDesignation( Designation );
            Temp.SetAgent( Agent );
            Temp.SetTemperature( Temperature );
            Temp.SetPollenCount( Count );
            Temp.SetAirIndex( Index );
            
            List.push_back(Temp);
            }
            InFile.close();
            }
            
            void Menu();
            int main()
            {
            int I = 0; 
            
            VectorList Station;
            string Command;
            
            while(true)
            {
            Menu();
            cout << "Enter Command: ";
            getline (cin, Command);
            cout << "\n\n";
            
            if (Command == "Add Stations")
            {
            Station.AddStations();
            I = 1;
            }
            if (Command == "Post Station Info" && I == 1)
            { 
            Station.PostStationInfo();
            I = 2; 
            }
            if (Command == "Quit")
            break;
            else 
            {
            if ( I == 1 )
            cout << "\nPlease Post Station Info\n";
            if (Command == "Daily Report" && I == 2)
            Station.DailyReport();
            if (Command == "High-Low Report" && I == 2)
            Station.HighLowReport();
            if (Command == "Daily Pollen Count" && I == 2)
            Station.PollenCount();
            if (Command == "Daily Air Quality Index" && I == 2)
            Station.AirQualityIndex();
            if (Command == "Change File Name")
            {
            string FName;
            cout << "Enter File Name: ";
            getline(cin, FName);
            Station.SetFileName(FName);
            cout << "File Name is Changed";
            }
            if (Command == "Save To File")
            { 
            Station.WriteToFile();
            cout << "File is saved\n";
            }
            if (Command == "Read From File")
            {
            Station.ReadFromFile();
            I = 2;
            cout << "Opened Saved File\n";
            }
            }
            }
            }
            
            void Menu()
            {
            cout << "\nChoices:";
            cout << "\n---------------------------";
            cout << "\n Add Stations";
            cout << "\n Post Station Info";
            cout << "\n Daily Report";
            cout << "\n High-Low Report";
            cout << "\n Daily Pollen Count";
            cout << "\n Daily Air Quality Index";
            cout << "\n Change File Name";
            cout << "\n Save To File";
            cout << "\n Read From File";
            cout << "\n Quit";
            cout << "\n---------------------------\n";
            }


    so, when I try to compile the programme, the compiler shows me a number of errors. And, among all the errors the first error it shows is in the line 27; the error says " invalid use of undefined type `class PollenAirQuality' ". And, I am not sure but I think that all other errors are the result of this error. Anyway, I hope that somebody will give me some suggesstions to fix the problem.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    You seem to be missing a closing brace '}' in your PollenAirQuality class definition. Insure you have a closing brace for each opening brace.

    Jim

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You have omitted a closing brace on the body of PollenAirQuality's GetPollenCount() member function.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Any chance you could be less specific than "it doesn't work"?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Could you also properly indent the code?
    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.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Thanks both Jimblumberg and Grumpy. You guys were right. I forgot to put the closing brace on one of the member function of the class-PollenAirQuality. I feel so stupid. I spent like at least one and half hour trying to figure out the error but could not see the missing closing brace.
    Anyway now the programme is running fine. But, the problem now I have is with the lowest temperature i.e, with the function VectorList::GetMinF(). The programme shows the highest temperature as the lowest temperature. Also, for some reason, the programme is not reading the file. So, there might be some problems with the function-VectorList::ReadFromFile().

    Also, Elysia, I am kind of a beginner in programming. So, I don't have too much knowledge about the proper indentation of the code. So, if you could tell me howo to properly indent the code, I would appreciate it.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    For the indentation issue check this link.

    For your file reading problems are you sure that the file is actually being opened? You should always check the stream state after trying to open a file.

    Also could you provide a small sample of your input file?

    Jim

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    Quote Originally Posted by jimblumberg View Post
    For the indentation issue check this link.

    For your file reading problems are you sure that the file is actually being opened? You should always check the stream state after trying to open a file.

    Also could you provide a small sample of your input file?

    Jim
    [indent]
    Jim, could you tell me what do you mean when you say "you should always check the stream state after trying to open a file"?

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    After you try to open your file check the stream state
    Code:
    fstream InFile(FileName.c_str(), ios::in);
    if(!InFile)
       // The file did not open properly do something about it here.
    Jim

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    Quote Originally Posted by jimblumberg View Post
    After you try to open your file check the stream state
    Code:
    fstream InFile(FileName.c_str(), ios::in);
    if(!InFile)
       // The file did not open properly do something about it here.
    Jim
    [indent]
    Jim, thanks for your help. Now, I don't have problems with reading the files from the disk or wrting the files on the disk.
    Last edited by philiplahm; 03-26-2011 at 07:24 PM. Reason: Double Post

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    If you are still having problems with the GetMinF() function displaying the maximum instead of the minimum you may want to change the greater than operator to the less than operator in you if statement
    Code:
    if ( (*ILister).GetTemperature() > minF)
    Is your maximum function working correctly? They should be almost the same.

    Jim

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    When I run the programme, it shows some completely random number as the lowest temperature. So, it seems like there is something wrong with the function-VectorList::GetMinF(). But, I could not figure out what exactly is the problem. So, any more help to solve this problem will be greatly appreciated.
    Here is the revised code for the programme:


    Code:
            #include <iostream>
            #include <string> 
            #include <vector>
            #include <fstream>
            
            using namespace std;
            
            
            class PollenAirQuality
            {
            public:
            PollenAirQuality() {PollenCount= AirIndex= 0; }
            void SetPollenCount(double Count) { PollenCount = Count; }
            double GetPollenCount() { return PollenCount;}
            void SetAirIndex(double Index) { AirIndex = Index; }
            double GetAirIndex() {return AirIndex; }
            
            protected:
            double PollenCount;
            double AirIndex;
            
            };
            
          
            
            class WeatherStation : public PollenAirQuality
            {
            public:
            WeatherStation();
            
            void SetDesignation(string ID) { StationDesignation = ID; }
            void SetAgent(string Agent) { StationAgent = Agent; }
            void SetTemperature(double Degree) { Temperature = Degree; }
            
            double Convert(double DegreeF);
            
            string GetDesignation() { return StationDesignation; }
            string GetAgent() { return StationAgent; }
            double GetTemperature() { return Temperature; }
            
            protected:
            string StationDesignation;
            string StationAgent; 
            double Temperature; 
            
            };
            
            WeatherStation::WeatherStation()
            {
            StationDesignation = "";
            StationAgent = "";
            Temperature = 0;
            }
            
            double WeatherStation::Convert(double degreeF)
            {
            double degreeC;
            
            // convert Fahrenheit to Celcius
            degreeC = ((degreeF - 32) * 5) / 9;
            
            return degreeC;
            }
            
            class VectorList
            {
            vector<WeatherStation> List;
            vector<WeatherStation>::iterator ILister;
            
            string FileName;
            
            public:
            VectorList() { FileName = "Temp"; }
            VectorList(string FName) { FileName = FName; }
            
            void AddStations();
            void PostStationInfo();
            void DailyReport();
            void HighLowReport();
            void PollenCount();
            void AirQualityIndex();
            double GetMaxF();
            double GetMinF();
            double GetAvgF();
            
            void SetFileName(string FName) { FileName = FName; }
            void WriteToFile();
            void ReadFromFile();
            
            };
            
            void VectorList::AddStations()
            {
            WeatherStation Station;
            string Designation, Agent;
            
            cout << "Enter Station Information Below, Stop To Quit\n";
            
            for (;;)
            {
            cout << "\n-------------------------------\n";
            
            cout << "Enter Weather Station Designation: ";
            getline (cin, Designation);
            if (Designation == "Stop")
            break;
            Station.SetDesignation( Designation );
            
            cout << "\nEnter Contact Person: ";
            getline (cin, Agent);
            if (Agent == "Stop")
            break;
            Station.SetAgent( Agent );
            
            cout << "\n-------------------------------\n";
            
            List.push_back(Station);
            
            }
            }
            void VectorList::PostStationInfo()
            { 
            double Degree, Count, Index;
            
            cout << "Enter reported temperatures: (in Fahrenheit) \n\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\n";
            cout << ILister->GetAgent();
            
            cout << "\nEnter Temperature:\t";
            cin >> Degree;
            ILister->SetTemperature( Degree );
            
            cout << "\n\tPollen Count:\t";
            cin >> Count;
            ILister->SetPollenCount( Count );
                           
            cout << "\n\tAir Quality Index:\t";
            cin >> Index;
            ILister->SetAirIndex( Index );
            
            cin.ignore(100, '\n');
            }
            }
            
            void VectorList::DailyReport()
            {
            cout << " NGS Daily Temperature Report \n";
            cout << "===========================================================\n";
            cout << "\t\t Fahrenheit(°F) \t Celsius (°C)";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << "\n-----------------------------------------------------------\n";
            cout << (*ILister).GetDesignation() << "\t\t ";
            cout << (*ILister).GetTemperature() << "\t\t\t" 
            << (*ILister).Convert( (*ILister).GetTemperature() );
            }
            
            cout << "\n-----------------------------------------------------------";
            cout << "\nMean Temperature: \t " << GetAvgF() // The first problem is here
            << "\t\t\t" << (*ILister).Convert(GetAvgF() );
            cout << "\n===========================================================\n\n";
            }
            
            void VectorList::HighLowReport()
            {
            cout << " NGS High-Low Report ";
            cout << "\n==========================================================";
            cout << "\n\t\t Fahrenheit(°F) \t Celsius (°C)";
            cout << "\n----------------------------------------------------------";
            cout << "\nLowest Temperature:\t " << GetMinF() //Second problem
            << "\t\t\t" << (*ILister).Convert( GetMinF() );
            cout << "\n----------------------------------------------------------";
            cout << "\nHighest Temperature:\t " << GetMaxF() //Third problem
            << "\t\t\t" << (*ILister).Convert( GetMaxF() );
            cout << "\n----------------------------------------------------------";
            cout << "\n==========================================================\n";
            }
            
            
            void VectorList::PollenCount()
            {
            
            cout << " NGS Daily Pollen Report\n";
            cout << "==================================\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\t\t" << ILister->GetPollenCount() << "\n";
            }
            cout << "==================================\n\n";
            }
            
            void VectorList:: AirQualityIndex()
            {
            cout << " NGS Air Quality Index  Report\n";
            cout << "==================================\n";
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            cout << ILister->GetDesignation() << ":\t\t" << ILister->GetAirIndex() << "\n";
            }
            cout << "==================================\n\n";
            }
            
            double VectorList::GetMaxF()
            {
            double maxF;
            
            maxF = ILister->GetTemperature();
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            // find the highest temperture in Fahrenheit
            if ( (*ILister).GetTemperature() > maxF)
            maxF = (*ILister).GetTemperature();
            }
            return maxF;
            }
            double VectorList::GetMinF()
            {
            double minF;
            
            minF = ILister->GetTemperature();
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            {
            // find the lowest temperture in Fahrenheit
            if ( (*ILister).GetTemperature() < minF)
            minF = (*ILister).GetTemperature();
            }
            return minF;
            }
            
            
            double VectorList::GetAvgF()
            {
            double Total = 0, Mean;
            
            for (ILister = List.begin(); ILister < List.end(); ILister++)
            Total += ILister->GetTemperature();
            
            Mean = Total / List.size();
            
            return Mean;
            }
            void VectorList::WriteToFile() 
            {
            fstream OutFile(FileName.c_str(), ios::out);
            
            for ( ILister = List.begin(); ILister < List.end(); ILister++)
            {
            OutFile << ILister->GetDesignation() << endl;
            OutFile << ILister->GetAgent() << endl;
            OutFile << ILister->GetTemperature() << endl;
            OutFile << ILister->GetPollenCount() << endl;
            OutFile << ILister->GetAirIndex() << endl;
            }
            
            OutFile.close();
            }
            
            void VectorList::ReadFromFile()
            {
            fstream InFile(FileName.c_str(), ios::in);
            
            string Designation, Agent;
            double Temperature, Count, Index;
            WeatherStation Temp;
            
            while(true)
            {
            getline(InFile, Designation); 
            getline(InFile, Agent);
            InFile >> Temperature;
            InFile >> Count;
            InFile >> Index;
            
            InFile.ignore(100, '\n'); 
            
            if(InFile.eof())
            break;
            
            Temp.SetDesignation( Designation );
            Temp.SetAgent( Agent );
            Temp.SetTemperature( Temperature );
            Temp.SetPollenCount( Count );
            Temp.SetAirIndex( Index );
            
            List.push_back(Temp);
            }
            InFile.close();
            }
            
            void Menu();
            int main()
            {
            int I = 0; 
            
            VectorList Station;
            string Command;
            
            while(true)
            {
            Menu();
            cout << "Enter Command: ";
            getline (cin, Command);
            cout << "\n\n";
            
            if (Command == "Add Stations")
            {
            Station.AddStations();
            I = 1;
            }
            if (Command == "Post Station Info" && I == 1)
            { 
            Station.PostStationInfo();
            I = 2; 
            }
            if (Command == "Quit")
            break;
            else 
            {
            if ( I == 1 )
            cout << "\nPlease Post Station Info\n";
            if (Command == "Daily Report" && I == 2)
            Station.DailyReport();
            if (Command == "High-Low Report" && I == 2)
            Station.HighLowReport();
            if (Command == "Daily Pollen Count" && I == 2)
            Station.PollenCount();
            if (Command == "Daily Air Quality Index" && I == 2)
            Station.AirQualityIndex();
            if (Command == "Change File Name")
            {
            string FName;
            cout << "Enter File Name: ";
            getline(cin, FName);
            Station.SetFileName(FName);
            cout << "File Name is Changed";
            }
            if (Command == "Save To File")
            { 
            Station.WriteToFile();
            cout << "File is saved\n";
            }
            if (Command == "Read From File")
            {
            Station.ReadFromFile();
            I = 2;
            cout << "Opened Saved File\n";
            }
            }
            }
            }
            
            void Menu()
            {
            cout << "\nChoices:";
            cout << "\n---------------------------";
            cout << "\n Add Stations";
            cout << "\n Post Station Info";
            cout << "\n Daily Report";
            cout << "\n High-Low Report";
            cout << "\n Daily Pollen Count";
            cout << "\n Daily Air Quality Index";
            cout << "\n Change File Name";
            cout << "\n Save To File";
            cout << "\n Read From File";
            cout << "\n Quit";
            cout << "\n---------------------------\n";
            }


    Just for information, when my actual lowest temperature was 48 Fahrenheit Celsius, the programmed showed the lowest temperature was -1.677.

    Quote Originally Posted by jimblumberg View Post
    If you are still having problems with the GetMinF() function displaying the maximum instead of the minimum you may want to change the greater than operator to the less than operator in you if statement
    Code:
    if ( (*ILister).GetTemperature() > minF)
    Is your maximum function working correctly? They should be almost the same.

    Jim

    Jim, I changed the greater than operator to the less than operator; however, now, it shows some random number, which is not even my input temperature, as the lowest temperature.
    Last edited by philiplahm; 03-26-2011 at 07:32 PM.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Please post a small sample of your input file.

    And how are you printing out this item?

    What are your inputs.

    Jim
    Last edited by jimblumberg; 03-26-2011 at 07:54 PM.

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    First, my maximum function is working properly; it shows the highest temperature correctly. The problem is with the lowest temperature. Anyway, here is my input file:


    Code:
        America   // Weather Station Designation
        Michael   // Name of person responsible to the weather station
        55      //Temperature in Fahrenheit
        2       // Pollen count
        5       //Air Quality Index
        Canada
        David
        53       //Temperature in Fahrenheit
        46
        52
        Germany
        Jennifer
        61         //Temperature in Fahrenheit
        25
        14
        England
        Veronica
        48          //Temperature in Fahrenheit
        1
        2



    For more information, when I run the programme with the above file as my input, it shows the lowest temperature as 3.25187e-317 in Fahrenheit and
    -17.7778 in Celsius. But, we all know that 48 in Fahrenheit and 8.88 in Celsius have to be the lowest temperature.

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    I changed the code for GetMinF() to this and the min temperature works ok.
    Code:
    double VectorList::GetMinF()
    {
    	double minF;
    
    	//minF = ILister->GetTemperature();
    	minF = 1000.0;
    I think the problem with your temperature conversion routine is that you are doing integer math.
    Code:
    double WeatherStation::Convert(double degreeF)
    {
    	double degreeC;
    
    	// convert Fahrenheit to Celcius
    	//degreeC = ((degreeF - 32) * 5) / 9; /// This is integer math
            degreeC = ((degreeF - 32.0) * 5.0) / 9.0;  // Should Be this
    	return degreeC;
    }
    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  2. Programme Efficiency
    By Cikotic in forum C Programming
    Replies: 3
    Last Post: 06-28-2004, 01:29 PM
  3. Gui Programme does'nt Compiles from DOS
    By Shadowhunt in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2003, 08:05 AM
  4. Simple C++ GUI programme does'nt run from dos
    By Shadowhunt in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:30 AM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM