I am writing my rpg program, and when the program asks for the user's name, the program puts the most recently hit key in the space. I can't figure out how to keep it from doing this.
This function executes first.
And this is the character.setName() that is called.PHP Code:void initPlayers(){
human.initialize(20, 5, 8, 80, "Warrior");
wizard.initialize(30, 8, 5, 70, "Wizard");
ghost.initialize(50, 0, 15, 60, "Specter");
// Get player type choice from the user
system("cls");
printf("Choose which character to assume:\n");
printf("1) Warrior\n");
printf("2) Wizard\n");
printf("Choice: ");
switch (getche()){
case '1':
character = human;
break;
case '2':
character = wizard;
break;
default:
character = ghost;
break;
}
character.setName();
}
PHP Code:void setName(){
printf("\nWhat is your name? ");
cin >> name;
}



LinkBack URL
About LinkBacks



