Thread: help

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

    help

    Hi i am very new to C++ could someone please take a look at this code and tell me what I am doing wrong I am a total noob, so if you are willing to help please be as specific as possible. Thank you in advance for any comments.
    [code
    struct info
    {
    char last1 [25];
    char first1 [25];
    double payrate;
    int hours;

    };
    [/code]

    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <c:\Documents and Settings\Pat\Desktop\prog15\struct15.cpp\struct15.cpp\struct15.cpp>
    
    void getdata(char last1[25], char first1[25], int count, double payrate[25]);
    
    using namespace std;
    
    int main ()
    {
    const int MAX = 25;
    	struct info employee[MAX];
    	int count = 5;
    	char (ret);
    	char last[25];
    	char first[25];
    	double payrate[25];
    
    getdata(last,first,count,payrate);
    
    
    	
    	return 0;
    
    }
    #include <c:\Documents and Settings\Pat\Desktop\prog15\getdata15.cpp\getdata15.cpp\get15.cpp>
    Code:
    void getdata(char last1[25], char first1[25], double count, double payrate[25])
    {
    	char (ret);
    for (int i=0; i<=count; i++)
    	{
    		cout << "input Last Name:"<< endl;
    		cin.getline >> (employee[i].last1,25);
    		cout << "Input First Name:" << endl;
    		cin.getline (employee[i].first1,25);
    		cout << "Input payrate:" << endl;
    		cin >> employee[i].payrate;
    		cout << "Input Hours Worked:" << endl;
    		cin >> employee[i].hours;
    		cin.get (ret);
    		return;
    	}
    
    
    
    
    
    
    	return;
    }
    error codes below:
    c:\documents and settings\pat\desktop\prog15\prog15.cpp\prog15.cpp\ main15.cpp(33) : error C2143: syntax error : missing ';' before 'return'
    1>c:\documents and settings\pat\desktop\prog15\getdata15.cpp\getdata1 5.cpp\get15.cpp(11) : error C2065: 'employee' : undeclared identifier
    1>c:\documents and settings\pat\desktop\prog15\getdata15.cpp\getdata1 5.cpp\get15.cpp(11) : error C2228: left of '.last1' must have class/struct/union
    1>c:\documents and settings\pat\desktop\prog15\getdata15.cpp\getdata1 5.cpp\get15.cpp(13) : error C2228: left of '.first1' must have class/struct/union
    1>c:\documents and settings\pat\desktop\prog15\getdata15.cpp\getdata1 5.cpp\get15.cpp(15) : error C2228: left of '.payrate' must have class/struct/union
    1>c:\documents and settings\pat\desktop\prog15\getdata15.cpp\getdata1 5.cpp\get15.cpp(17) : error C2228: left of '.hours' must have class/struct/union

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. while it is possible #include <c:\Documents and Settings\Pat\Desktop\prog15\struct15.cpp\struct15. cpp\struct15.cpp>
    why do you need it?

    - to include files from the current folder use #include "filename.h"
    - cpp in most cases no need to include - only h-files should be included to notify compiler about function prototypes and class declarations
    - several cpp-files can be compiled together without including one-another
    2. Where is your employee struct or class defined?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

    thank you:)

    where should i include the employee struct class and what is the porper syntax?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Filename.h
    ------------
    Code:
    struct employee
    {
       string emp_name;
    };
    -----------------
    filename.cpp
    Code:
    #include "Filename.h"
    
    struct employee Myemployee;
    ------------

    Something like that
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

    Smile thanks

    thank you very much

Popular pages Recent additions subscribe to a feed