I'm doing a Lab assignment for my C++ class, but I'm stuck on some errors which I can't understand. I need someone expertise here. Below is my code. I supposes to run them and give me the values of playername, playerid, currentlevel and topfivescore.
You mention you are getting errors, but you didn't mention which errors you are getting?
Does the program compile? If not, which compilation errors do you get? Does the program crash, if so with which error? Are you expecting different output, if so, which output do you get and which do you expect?
Please let us know the errors you get and we'll be more equipped to help you.
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
'GamePlayer::setplayerName' : cannot convert parameter 1 from 'const char [5]' to 'char'
'GamePlayer::setplayerID' : cannot convert parameter 1 from 'const char [9]' to 'char'
Note that using std::string instead of char-arrays is a lot safer and recommended practice, but since it's an assignment you should probably use what you have learnt.
You are most likely experiencing the downside of using raw pointers and C-strings: segmentation faults.
These occur when your program tries to access memory that is outside the bounds of the memory provided to it by the operating system, or when you try to free unallocated memory.
If you have a debugger they can usually help you track these errors down. Clicking "break" may actually take you to a backtrace of what has happened. ANother way to figure this out is to put a std::cout statement after every line in main(), so you have an idea which function is causing the error.
Perhaps try that and get back to us with your revised code, so we can have a look.