help

This is a discussion on help within the C++ Programming forums, part of the General Programming Boards category; could anyone tell me where i am messing this up please? Code: struct empinfo{ char name[21]; char name1[21]; int hours; ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    help

    could anyone tell me where i am messing this up please?

    Code:
    struct empinfo{
    	char name[21];
    	char name1[21];
    	int hours;
    	float payrate;
    };
    Code:
    #include <c:\Documents and Settings\Pat\Desktop\Copy of New Folder (3)\empinfo.h\m15.cpp\struct15.cpp>
      extern void getempdata(struct empinfo emp1[], int &count1,int MAX1);
    int main()
    { const int MAX =25;
    struct empinfo emps[MAX];
    int count;
    getempdata(emps,count,MAX);
    return 0;
    }
    Code:
    #include <iostream>
    #include <c:\Documents and Settings\Pat\Desktop\New Folder (3)\m15.cpp\m15.cpp\struct15.cpp>
    using namespace std;
    
    void getempdata(struct empinfo emp1[], int &count1, int MAX)
    {
    char ans,ret;
    
    	count1 =0;
    	
    	while (((ans=='Y')||(ans =='y'))&&(count1<MAX))
    	{
    		cout << "tnput last name:";
    		cin.getline (emp1[count1].name,21);
    		cout << "input first name:";
    		cin.getline (emp1[count1].name1,21);
    		cout << "input hours:";
    		cin >> emp1[count1].hours;
    		cout << "input payrate:";
    		cin >> emp1[count1].payrate;
    		count1++;
    		cout << "input another - Y or N:";
    		cin >> ans;
    		cin.get(ret);
    	}
    	
    	return;
    }
    errors

    >------ Build started: Project: main15.cpp, Configuration: Debug Win32 ------
    1>Compiling...
    1>main15.cpp
    1>Linking...
    1>main15.obj : error LNK2019: unresolved external symbol "void __cdecl getempdata(struct empinfo * const,int &,int)" (?getempdata@@YAXQAUempinfo@@AAHH@Z) referenced in function _main
    1>C:\Documents and Settings\Pat\Desktop\Copy of New Folder (3)\main15.cpp\Debug\main15.cpp.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Documents and Settings\Pat\Desktop\Copy of New Folder (3)\main15.cpp\main15.cpp\Debug\BuildLog.htm"
    1>main15.cpp - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,747
    "Help" is not a thread title.
    help
    could I get a bit more help
    help

    Why are you #including code inside code?

    Where is your struct actually declared, other than in your post?

    As a single file, does this work?
    Code:
    #include <iostream>
    using namespace std;
    
    // This would go into empinfo.h
    struct empinfo{
    	char name[21];
    	char name1[21];
    	int hours;
    	float payrate;
    };
    extern void getempdata(struct empinfo emp1[], int &count1,int MAX1);
    
    // This would go into empinfo.cpp
    void getempdata(struct empinfo emp1[], int &count1, int MAX)
    {
    char ans,ret;
    
    	count1 =0;
    	
    	while (((ans=='Y')||(ans =='y'))&&(count1<MAX))
    	{
    		cout << "tnput last name:";
    		cin.getline (emp1[count1].name,21);
    		cout << "input first name:";
    		cin.getline (emp1[count1].name1,21);
    		cout << "input hours:";
    		cin >> emp1[count1].hours;
    		cout << "input payrate:";
    		cin >> emp1[count1].payrate;
    		count1++;
    		cout << "input another - Y or N:";
    		cin >> ans;
    		cin.get(ret);
    	}
    	
    	return;
    }
    
    // This would go into main.cpp
    int main()
    { const int MAX =25;
      struct empinfo emps[MAX];
      int count;
      getempdata(emps,count,MAX);
      return 0;
    }
    As 3 files, it would be like this
    Code:
    // This would go into empinfo.h
    struct empinfo{
    	char name[21];
    	char name1[21];
    	int hours;
    	float payrate;
    };
    extern void getempdata(struct empinfo emp1[], int &count1,int MAX1);
    Code:
    #include <iostream>
    #include "empinfo.h"
    using namespace std;
    
    // This would go into empinfo.cpp
    void getempdata(struct empinfo emp1[], int &count1, int MAX)
    {
    char ans,ret;
    
    	count1 =0;
    	
    	while (((ans=='Y')||(ans =='y'))&&(count1<MAX))
    	{
    		cout << "tnput last name:";
    		cin.getline (emp1[count1].name,21);
    		cout << "input first name:";
    		cin.getline (emp1[count1].name1,21);
    		cout << "input hours:";
    		cin >> emp1[count1].hours;
    		cout << "input payrate:";
    		cin >> emp1[count1].payrate;
    		count1++;
    		cout << "input another - Y or N:";
    		cin >> ans;
    		cin.get(ret);
    	}
    	
    	return;
    }
    Code:
    #include <iostream>
    #include "empinfo.h"
    using namespace std;
    // This would go into main.cpp
    int main()
    { const int MAX =25;
      struct empinfo emps[MAX];
      int count;
      getempdata(emps,count,MAX);
      return 0;
    }
    Your project should contain just main.cpp and empinfo.cpp
    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

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