can anyone help me with these errors??

This is a discussion on can anyone help me with these errors?? within the C++ Programming forums, part of the General Programming Boards category; can u help me with these errors??and ye i realize its a little outdated but its jus he book im ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    can anyone help me with these errors??

    can u help me with these errors??and ye i realize its a little outdated but its jus he book im using i like it better than most and i cant find its updated version


    #include <iostream.h>
    #include <fstream.h>
    struct jobInfo
    {
    short code;
    long salary;
    }
    //function prototypes
    void fillArray(ifstream, jobInfo employ[],short);
    void searchAndDisplay(short, jobInfo[],short);

    void main()
    {
    //declare and intilize varaible
    short searchCode = 0;
    //declare and initialize the array
    jobInfo job[10] = {0,0};
    //open file for input
    ifstream infile;
    infile.open("codes.dat",ios::in);
    //verify that open was successful
    if (!infile.fail())//open was successful
    {
    //fill arrays with data
    fillArray(infile, Job, 10);
    //close file
    infile.close();
    //get a code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    while (searchCode != 0)
    {
    //search the array for the code and display the salary
    searchAndDisplay(searchCode, job, 10);
    //get another code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    }//end while
    }
    else
    cout<<"error opening file\n";
    //end if
    }//end main function
    void fillArray(ifstream inEmp, jobInfo employ[],short size)
    {
    //this function fills the arrays with data from a file
    for(short x = 0; x < size; x = x+ 1)
    {
    //enter data from a file into arrays
    inEmp >>employ[x].code;
    inEmp.ignore(1);
    inEmp>>employ[x].salary;
    inEmp.ignore(1);
    }//end for
    }//end of fillArray function
    void searchAndDisplay(short inputCode,jobInfo employ[],short size)
    {
    /*this function searches for the code in the array
    if the code is in the array, the salary is displayed
    if the code is not in the array, a message is displayed*/
    short x = 0;
    char found = 'F';
    while (x<size && found == 'F')
    {
    if(employ[x].code == inputCode)//code is in the array
    {
    cout<<"Salary: "<<employ[x].salary<<"\n\n";
    found = 'T';
    }
    else
    //add 1 to counter variable
    x = x+ 1 ;
    //end if
    }//end while
    if(found == 'F')//code is not in the array
    cout<<"The salary is not the available.\n\n";
    //end if
    }//end of searchAndDisplay function
    //end of code





    --------------------Configuration: array - Win32 Debug--------------------
    Compiling...
    array.cpp
    C:\Windows\Desktop\c++\array.cpp(9) : error C2628: 'jobInfo' followed by 'void' is illegal (did you forget a ';'?)
    C:\Windows\Desktop\c++\array.cpp(25) : error C2065: 'Job' : undeclared identifier
    C:\Windows\Desktop\c++\array.cpp(47) : error C2556: 'void __cdecl fillArray(class ifstream,struct jobInfo [],short)' : overloaded function differs only by return type from 'struct jobInfo __cdecl fillArray(class ifstream,struct jobInfo [],short)'
    C:\Windows\Desktop\c++\array.cpp(9) : see declaration of 'fillArray'
    C:\Windows\Desktop\c++\array.cpp(47) : error C2371: 'fillArray' : redefinition; different basic types
    C:\Windows\Desktop\c++\array.cpp(9) : see declaration of 'fillArray'
    Error executing cl.exe.

    array.obj - 4 error(s), 0 warning(s)
    hooch

  2. #2
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    Please use the code tags (the # button). It's too hard to read with no indenting.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    559

    Re: can anyone help me with these errors??

    Comments added. You declare job but use Job

    Originally posted by ssjnamek
    can u help me with these errors??and ye i realize its a little outdated but its jus he book im using i like it better than most and i cant find its updated version


    #include <iostream.h>
    #include <fstream.h>
    struct jobInfo
    {
    short code;
    long salary;
    }
    //function prototypes
    void fillArray(ifstream, jobInfo employ[],short); // Where does employ come from?
    void searchAndDisplay(short, jobInfo[],short);

    void main()
    {
    //declare and intilize varaible
    short searchCode = 0;
    //declare and initialize the array
    jobInfo job[10] = {0,0};
    //open file for input
    ifstream infile;
    infile.open("codes.dat",ios::in);
    //verify that open was successful
    if (!infile.fail())//open was successful
    {
    //fill arrays with data
    fillArray(infile, Job, 10); // Job not declared - job was
    //close file
    infile.close();
    //get a code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    while (searchCode != 0)
    {
    //search the array for the code and display the salary
    searchAndDisplay(searchCode, job, 10);
    //get another code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    }//end while
    }
    else
    cout<<"error opening file\n";
    //end if
    }//end main function
    void fillArray(ifstream inEmp, jobInfo employ[],short size)
    {
    //this function fills the arrays with data from a file
    for(short x = 0; x < size; x = x+ 1)
    {
    //enter data from a file into arrays
    inEmp >>employ[x].code;
    inEmp.ignore(1);
    inEmp>>employ[x].salary;
    inEmp.ignore(1);
    }//end for
    }//end of fillArray function
    void searchAndDisplay(short inputCode,jobInfo employ[],short size)
    {
    /*this function searches for the code in the array
    if the code is in the array, the salary is displayed
    if the code is not in the array, a message is displayed*/
    short x = 0;
    char found = 'F';
    while (x<size && found == 'F')
    {
    if(employ[x].code == inputCode)//code is in the array
    {
    cout<<"Salary: "<<employ[x].salary<<"\n\n";
    found = 'T';
    }
    else
    //add 1 to counter variable
    x = x+ 1 ;
    //end if
    }//end while
    if(found == 'F')//code is not in the array
    cout<<"The salary is not the available.\n\n";
    //end if
    }//end of searchAndDisplay function
    //end of code





    --------------------Configuration: array - Win32 Debug--------------------
    Compiling...
    array.cpp
    C:\Windows\Desktop\c++\array.cpp(9) : error C2628: 'jobInfo' followed by 'void' is illegal (did you forget a ';'?)
    C:\Windows\Desktop\c++\array.cpp(25) : error C2065: 'Job' : undeclared identifier
    C:\Windows\Desktop\c++\array.cpp(47) : error C2556: 'void __cdecl fillArray(class ifstream,struct jobInfo [],short)' : overloaded function differs only by return type from 'struct jobInfo __cdecl fillArray(class ifstream,struct jobInfo [],short)'
    C:\Windows\Desktop\c++\array.cpp(9) : see declaration of 'fillArray'
    C:\Windows\Desktop\c++\array.cpp(47) : error C2371: 'fillArray' : redefinition; different basic types
    C:\Windows\Desktop\c++\array.cpp(9) : see declaration of 'fillArray'
    Error executing cl.exe.

    array.obj - 4 error(s), 0 warning(s)

  4. #4
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    Are you sure you can pass an infile to a function? I'm not sure on that one, and if that's not the problem, I'm stumped.

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I think its the semicolon that u r missing after the declaration of the jobinfo structure.

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    hmm well i dunt kno but thats how it was in the book
    hooch

  7. #7
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    golfinguy is right
    Code:
    struct jobInfo 
    { 
    short code; 
    long salary; 
    }
    should be
    Code:
    struct jobInfo 
    { 
    short code; 
    long salary; 
    };

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    i fixed that little error in the struct and i got a new set of errors



    #include <iostream.h>
    #include <fstream.h>
    struct jobInfo
    {
    short code;
    long salary;
    };
    //function prototypes
    void fillArray(ifstream, jobInfo employ[],short);
    void searchAndDisplay(short, jobInfo[],short);

    void main()
    {
    //declare and intilize varaible
    short searchCode = 0;
    //declare and initialize the array
    jobInfo job[10] = {0,0};
    //open file for input
    ifstream infile;
    infile.open("codes.dat",ios::in);
    //verify that open was successful
    if (!infile.fail())//open was successful
    {
    //fill arrays with data
    fillArray(infile,jobInfo Job, 10);
    //close file
    infile.close();
    //get a code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    while (searchCode != 0)
    {
    //search the array for the code and display the salary
    searchAndDisplay(searchCode, job, 10);
    //get another code
    cout<<"enter the code (0 to stop)\n";
    cin>>searchCode;
    cin.ignore(100,'\n');
    }//end while
    }
    else
    cout<<"error opening file\n";
    //end if
    }//end main function
    void fillArray(ifstream inEmp, jobInfo employ[],short size)
    {
    //this function fills the arrays with data from a file
    for(short x = 0; x < size; x = x+ 1)
    {
    //enter data from a file into arrays
    inEmp >>employ[x].code;
    inEmp.ignore(1);
    inEmp>>employ[x].salary;
    inEmp.ignore(1);
    }//end for
    }//end of fillArray function
    void searchAndDisplay(short inputCode,jobInfo employ[],short size)
    {
    /*this function searches for the code in the array
    if the code is in the array, the salary is displayed
    if the code is not in the array, a message is displayed*/
    short x = 0;
    char found = 'F';
    while (x<size && found == 'F')
    {
    if(employ[x].code == inputCode)//code is in the array
    {
    cout<<"Salary: "<<employ[x].salary<<"\n\n";
    found = 'T';
    }
    else
    //add 1 to counter variable
    x = x+ 1 ;
    //end if
    }//end while
    if(found == 'F')//code is not in the array
    cout<<"The salary is not the available.\n\n";
    //end if
    }//end of searchAndDisplay function
    //end of code



    --------------------Configuration: array - Win32 Debug--------------------
    Compiling...
    array.cpp
    C:\Windows\Desktop\c++\array.cpp(25) : error C2275: 'jobInfo' : illegal use of this type as an expression
    C:\Windows\Desktop\c++\array.cpp(4) : see declaration of 'jobInfo'
    C:\Windows\Desktop\c++\array.cpp(25) : error C2146: syntax error : missing ')' before identifier 'Job'
    C:\Windows\Desktop\c++\array.cpp(25) : error C2059: syntax error : ')'
    Error executing cl.exe.

    array.obj - 3 error(s), 0 warning(s)
    hooch

  9. #9
    Unregistered
    Guest
    >> jobInfo job[10] = {0,0};

    I could definitely be wrong about this but I don't think you can initialize struct data in an array that way. I think you need to do something like this:

    jobinfo job[10];

    for(int i = 0; i < 10; i++)
    {
    job[i].code = 0;
    job[i].salary = 0.00;
    }



    >> jobInfo employ[],
    you could try leaving out the word employ in the above segment of the declaration of fillArray(). Probably won't make a difference however.

    >> fillArray(infile,jobInfo Job, 10);
    using the type name jobInfo in the function call, however, is a definite no no. This, I think is the source of the first, third, and fourth error messages listed. Also, Job should be job in the function call, although that is not listed as an error yet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 03:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

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