Like Tree4Likes
  • 1 Post By jimblumberg
  • 1 Post By jimblumberg
  • 2 Post By Salem

beginner error help

This is a discussion on beginner error help within the C++ Programming forums, part of the General Programming Boards category; I have a program and I need help solving my errors, any help would be appreciated. Oh, and I'm using ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    6

    beginner error help

    I have a program and I need help solving my errors, any help would be appreciated. Oh, and I'm using code blocks.

    Code:
    #include<iostream>
    #include <string>
    #include<fstream>
    #include <iomanip>
    using namespace std ;
    
    
    void floor_level (int, string);
    string office_name (int);
    string Parties (char);
    char party;
    
    
      int main()
       {
             int District_number,room_number;
             string name, office_building, office, floor, state, building_name, party_name;
             char party;
             int count1=0, count2=0;
    
    
    
    
             ifstream inFile;    //input file stream variable
             string filename;    // name of the input file
    
    
    
    
            cout << "Enter the name of the input file:  " ;
            cin >> filename;
    
    
            inFile.open(filename.c_str ()  );
    
    
            //inData.open("numbers1.txt");
            if ( !inFile)
             {
                  cout << " input file not found \n";
                  return 1;
             }
            getline(inFile, state);
    
    
            cout<<"\n==========================================\n";
            cout<<"|  Directory for the representatives from  |\n";
            cout<<"|                                          |\n";
            cout<<"|              "<<state<<"                 |\n";
            cout<<"|                                          |\n";
            cout<<"============================================";
    
    
    
    
    
    
             while ( inFile!=0)
             {
             inFile>>District_number>>name>>party>>room_number>>building_name;
    
    
             building_name=office(office_building);
             party_name=Parties(party);
    
    
             cout<<left<<"District"<<District_number;
             cout<<" "<<party_name<<"\n";
             cout<<setw(15)<<name<<"\t";
             cout<<setw(15)<<" "<<building_name;
             cout<<left<<" Room "<<room_number;
             floor(room_number,office_building);
             cout<<"\n\n";
    
    
                    if(party=='R')
                        {
                            count1++;
                        }
                    else if(party=='D')
                        {
                            count2++;
                        }
             }
    
    
        cout<<"Number of Republicans in "<<state<<": "<<count1<<"\n";
        cout<<"Number of Democrats in "<<state<<": "<<count2<<"\n";
    
    
        cout<<"\nProgrammer: Josef Morken\n";
        cout<<"Date:3/22/2013\n";
        cout<<"CRN:23856\n";
    
    
             return 0;
       }
        void floor_level(int room_number, string office_building)
        {
            if (office_building == "CHOB")
            {
    
    
            if (room_number<200)
                cout<<"First Floor";
            else if(room_number>200 && room_number<300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>300 && room_number<400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>400 && room_number<500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>500 && room_number<600)
            {
                cout<<"Fifth Floor";
            }
            }
        if (office_building == "LHOB")
            {
    
    
            if (room_number<1200)
                cout<<"First Floor";
            else if(room_number>1200 && room_number<1300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>1300 && room_number<1400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>1400 && room_number<1500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>1500 && room_number<1600)
            {
                cout<<"Fifth Floor";
            }
            }
        if (office_building == "RHOB")
            {
    
    
            if (room_number<2200)
                cout<<"First Floor";
            else if(room_number>2200 && room_number<2300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>2300 && room_number<2400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>2400 && room_number<2500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>2500 && room_number<2600)
            {
                cout<<"Fifth Floor";
            }
            }
            string office_names(string office_names)
            {
                 string buildingname;
                if (office_names=="CHOB")
                   buildingname = "Cannon Building";
                if (office_names=="LHOB")
                   buildingname = "Longworth Building";
                if (office_names=="RHOB")
                   buildingname = "Rayburn Building";
    
    
                return buildingname;
    
    
            }
        }
    string Parties(char party)
    {
         string Party_names;
          if (Party_names=='R')
               cout<<"Republican";
           else if (Party_names=='D')
               cout<<"Democrat";
    
    
           return Party_names;
    }


    Morken_J_Prj3.cpp

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    What problems are you having? If you get compiler errors post the complete error messages.

    Jim
    stahta01 likes this.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    Here's a picture of the errors.
    Name:  c++.jpg
Views: 173
Size:  98.2 KB

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    You need to cut and past the errors into your post, I for one can't even see the error messages much less read them.

    Jim

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    Sorry about that, is this better?
    Code:
    Z:\Morken_J_Prj3.cpp||In function 'int main()':|
    Z:\Morken_J_Prj3.cpp|50|error: no match for call to '(std::string {aka std::basic_string<char>}) (std::string&)'|
    Z:\Morken_J_Prj3.cpp|58|error: no match for call to '(std::string {aka std::basic_string<char>}) (int&, std::string&)'|
     
    Z:\Morken_J_Prj3.cpp||In function 'void floor_level(int, std::string)':|
    Z:\Morken_J_Prj3.cpp|152|error: a function-definition is not allowed here before '{' token|
    Z:\Morken_J_Prj3.cpp||In function 'std::string Parties(char)':|
    Z:\Morken_J_Prj3.cpp|168|error: no match for 'operator==' in 'Party_names == 'R''|
    Z:\Morken_J_Prj3.cpp|168|note: candidates are:|

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    Where have you declared or implemented a function with the name of office()?
    stahta01 likes this.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    Quote Originally Posted by theevilm View Post
    Sorry about that, is this better?
    Code:
    Z:\Morken_J_Prj3.cpp||In function 'int main()':|
    Z:\Morken_J_Prj3.cpp|50|error: no match for call to '(std::string {aka std::basic_string<char>}) (std::string&)'|
    Z:\Morken_J_Prj3.cpp|58|error: no match for call to '(std::string {aka std::basic_string<char>}) (int&, std::string&)'|
     
    Z:\Morken_J_Prj3.cpp||In function 'void floor_level(int, std::string)':|
    Z:\Morken_J_Prj3.cpp|152|error: a function-definition is not allowed here before '{' token|
    Z:\Morken_J_Prj3.cpp||In function 'std::string Parties(char)':|
    Z:\Morken_J_Prj3.cpp|168|error: no match for 'operator==' in 'Party_names == 'R''|
    Z:\Morken_J_Prj3.cpp|168|note: candidates are:|
    Line 50 shown below; what do you think the type of office is?
    In C, I would say a function; in C++, maybe a class.
    What is it in your program?
    building_name=office(office_building);
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    I have changed some things, it might answer your question;

    Code:
    #include<iostream>
    #include <string>
    #include<fstream>
    #include <iomanip>
    using namespace std ;
    
    
    void floor_level (int, string);
    string office_name (string);
    string Parties (char);
    char party;
    
    
      int main()
       {
             int District_number,room_number;
             string name, office_building, office, state, buildingname, Party_names;
             char party;
             int count1=0, count2=0;
    
    
    
    
             ifstream inFile;    //input file stream variable
             string filename;    // name of the input file
    
    
    
    
            cout << "Enter the name of the input file:  " ;
            cin >> filename;
    
    
            inFile.open(filename.c_str ()  );
    
    
            //inData.open("numbers1.txt");
            if ( !inFile)
             {
                  cout << " input file not found \n";
                  return 1;
             }
            getline(inFile, state);
    
    
            cout<<"\n==========================================\n";
            cout<<"|  Directory for the representatives from  |\n";
            cout<<"|                                          |\n";
            cout<<"|              "<<state<<"                 |\n";
            cout<<"|                                          |\n";
            cout<<"============================================";
    
    
    
    
    
    
             while ( inFile!=0)
             {
             inFile>>District_number>>name>>party>>room_number>>office_building;
    
    
             building_name=office_name(office_building);
             Party_names=Parties(party);
    
    
             cout<<left<<"District"<<District_number;
             cout<<" "<<Party_names<<"\n";
             cout<<setw(15)<<name<<"\t";
             cout<<setw(15)<<" "<<building_name;
             cout<<left<<" Room "<<room_number;
             floor_level(room_number,office_building);
             cout<<"\n\n";
    
    
                    if(party=='R')
                        {
                            count1++;
                        }
                    else if(party=='D')
                        {
                            count2++;
                        }
             }
    
    
        cout<<"Number of Republicans in "<<state<<": "<<count1<<"\n";
        cout<<"Number of Democrats in "<<state<<": "<<count2<<"\n";
    
    
        cout<<"\nProgrammer: Josef Morken\n";
        cout<<"Date:3/22/2013\n";
        cout<<"CRN:23856\n";
    
    
             return 0;
       }
        void floor_level(int room_number, string office_building)
        {
            if (office_building == "CHOB")
            {
    
    
            if (room_number<200)
                cout<<"First Floor";
            else if(room_number>200 && room_number<300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>300 && room_number<400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>400 && room_number<500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>500 && room_number<600)
            {
                cout<<"Fifth Floor";
            }
            }
        if (office_building == "LHOB")
            {
    
    
            if (room_number<1200)
                cout<<"First Floor";
            else if(room_number>1200 && room_number<1300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>1300 && room_number<1400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>1400 && room_number<1500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>1500 && room_number<1600)
            {
                cout<<"Fifth Floor";
            }
            }
        if (office_building == "RHOB")
            {
    
    
            if (room_number<2200)
                cout<<"First Floor";
            else if(room_number>2200 && room_number<2300)
            {
                cout<<"Second Floor";
            }
            else if(room_number>2300 && room_number<2400)
            {
                cout<<"Third Floor";
            }
    
    
            else if(room_number>2400 && room_number<2500)
            {
                cout<<"Fourth Floor";
            }
            else if(room_number>2500 && room_number<2600)
            {
                cout<<"Fifth Floor";
            }
            }
        string office_names(string office_names);
        {
                 string buildingname;
                if (office_names=="CHOB")
                   buildingname = "Cannon Building";
                if (office_names=="LHOB")
                   buildingname = "Longworth Building";
                if (office_names=="RHOB")
                   buildingname = "Rayburn Building";
    
    
                return buildingname;
    
    
        }
        }
    string Parties(char party)
    {
         string Party_names;
          if (Party_names=='R')
               Party_names="Republican";
           else if (Party_names=='D')
               Party_names="Democrat";
    
    
           return Party_names;
    }

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    Post the new errors and warning.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    Hint: Look at the bold words.
    string Parties(char party)
    string Party_names;
    if (Party_names=='R')
    Party_names="Republican";
    else if (Party_names=='D')
    Party_names="Democrat";


    return Party_names;
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  11. #11
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    Code:
    Z:\Morken_J_Prj3.cpp|50|error: 'building_name' was not declared in this scope|
    Z:\Morken_J_Prj3.cpp||In function 'int main()':|
    Z:\Morken_J_Prj3.cpp|50|error: 'building_name' was not declared in this scope|
    Z:\Morken_J_Prj3.cpp||In function 'void floor_level(int, std::string)':|
    Z:\Morken_J_Prj3.cpp|154|error: comparison between distinct pointer types 'std::string (*)(std::string) {aka std::basic_string<char> (*)(std::basic_string<char>)}' and 'const char*' lacks a cast [-fpermissive]|
    Z:\Morken_J_Prj3.cpp|156|error: comparison between distinct pointer types 'std::string (*)(std::string) {aka std::basic_string<char> (*)(std::basic_string<char>)}' and 'const char*' lacks a cast [-fpermissive]|
    Z:\Morken_J_Prj3.cpp|158|error: comparison between distinct pointer types 'std::string (*)(std::string) {aka std::basic_string<char> (*)(std::basic_string<char>)}' and 'const char*' lacks a cast [-fpermissive]|
    Z:\Morken_J_Prj3.cpp|161|error: return-statement with a value, in function returning 'void' [-fpermissive]|
    Z:\Morken_J_Prj3.cpp||In function 'std::string Parties(char)':|
    Z:\Morken_J_Prj3.cpp|168|error: no match for 'operator==' in 'Party_names == 'R''|
    Z:\Morken_J_Prj3.cpp|168|note: candidates are:|
    c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\postypes.h|218|note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)|
    c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\postypes.h|218|note:   template argument deduction/substitution failed:|
    Z:\Morken_J_Prj3.cpp|168|note:   'std::string {aka std::basic_string<char>}' is not derived from 'const std::fpos<_StateT>'|

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    I fixed the building name declaration.

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    Second hint; my last hint tonight. Note: I am a C Programmer learning C++.

    When this type of code gives me errors.
    Code:
    if (office_names=="CHOB")
    I try this; might not be best fix.

    Code:
    if (office_names==string("CHOB"))
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    You should begin by indenting the code properly before doing anything else.
    SourceForge.net: Indentation - cpwiki

    The ; at the end of line 175 (post #8) is a killer.
    stahta01 and Elysia like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner File I/O Error
    By plain in forum C Programming
    Replies: 6
    Last Post: 09-15-2009, 11:30 PM
  2. Beginner Error
    By SvenRL in forum C Programming
    Replies: 5
    Last Post: 07-07-2009, 01:02 AM
  3. Beginner Error
    By strokebow in forum C++ Programming
    Replies: 10
    Last Post: 09-19-2008, 05:12 PM
  4. compile error (beginner)
    By eth0 in forum C++ Programming
    Replies: 11
    Last Post: 12-30-2003, 02:15 PM
  5. Help with error beginner
    By coloughl in forum C Programming
    Replies: 5
    Last Post: 05-17-2002, 09:01 PM

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