Well, I see that you have several problems.
It looks like you wanted to use strings, but in fact are using cstrings (as in the language C, not C++. C++ can use cstrings though).
1 2
|
char name[EMP_NUM][EMP_SCORES];
char id[EMP_NUM][EMP_SCORES];
|
Defines a
two dimensional array (arrays in C/C++ are fixed lenth)
of characters, not of strings. If you WANTED to use cstrings you need to be aware that a cstring is an array of characters ending with a null character '\0'.
So the cstring declaration
char hi[]="Hello";
actually defines an array of 6 character elements
hi[0] == 'H'
hi[1] == 'e'
hi[2] == 'l'
hi[3] == 'l'
hi[4] == 'o'
hi[5] == '\0' |
That can be treated (sort of) like the strings of other languages.
To use cstrings you would need to define name and id as
three dimensional arrays like this:
1 2
|
char name[MAX_NAME_LENGTH][EMP_NUM][EMP_SCORES];
char id[MAX_ID_LENGTH][EMP_NUM][EMP_SCORES];
|
But could still access it as a cstring like this:
name[num][0];
. Weird, huh?
I
recommend that you go with strings, not cstrings.
To do this, since you have already
#include <string>
, you will have to simply change your name and id variables from char to string:
1 2
|
string name[EMP_NUM][EMP_SCORES];
string id[EMP_NUM][EMP_SCORES];
|
Whichever type of string you choose to use, you'll need to use the getline() function, rather than cin, because cin stops at the first whitespace it runs into (' ', '\t', '\n').
1 2
|
cin.getline(name, MAX_NAME_LENGTH); // for cstrings
getline(cin, name); // for strings
|
So the employee's first name got put into
name, the last name got put into
ID, and then the carrage-return was causing the other the other cin's trouble because they were looking for an
int and could only find a carrage-return. Or something like that.
Here are links on cstring getline
http://www.cplusplus.com/reference/iostream/istream/getline/
and the string getline
http://www.cplusplus.com/reference/string/getline/
Personally it seems that you're jumping ahead of where you should be starting out. There are some very good C++ tutorials on this website, l think you might benefit from checking them out.