In C++, classes are generally preferred, with structs being consider just little above primitives for usage cases. In reality, structs and classes can be near identical, so it's more an expression of intent.
You could do something like this:
CODE
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
class Player {
private:
int difficulty;
public:
Player(int difficulty);
int getDifficulty();
void display(ostream& out);
};
Player::Player(int difficulty) { this->difficulty = difficulty; }
int Player::getDifficulty() { return this->difficulty; }
void Player::display(ostream& out) {
out << "Player: " << this->difficulty << endl;
}
Player * playerCreate() {
cout << endl;
cout << "Please select a difficulty from 1(easiest) to 3(hardest)." << endl;
int difficulty = -1;
while (true) {
cin >> difficulty;
if (difficulty >=1 && difficulty <= 3) {
return new Player(difficulty);
}
cout << "\nThat is not a valid choice please choose again.\n";
}
}
char getResponseChar() {
char ch;
cin >> ch;
return tolower(ch);
}
int main() {
Player *player = NULL;
srand ( time(NULL) ); //start srand
while (true) {
cout << "Hello, and welcome to Adventure Land." << endl;
cout << "Would you like to start a new game? (q to quit)" << endl;
char newGame = getResponseChar();
if (newGame == 'y') {
player = playerCreate();
player->display(cout);
delete(player);
} else if (newGame =='q') {
break;
} else {
cout << endl << "That is not a valid choice please choose again." << endl;
}
}
cout << endl << "Thank you for playing!" << endl;
return 0;
}