Okay, so in my continuing quest to make a text adventure and learn C++ in the process, I found in the tutorial a nifty way for the user to enter long strings without having the program flip out if there's a space in the string. I wanted to let players enter their name, or have the option of a few pre-set names, so I defined variables and built a switch case like so:
variable/array
Code:
int playername;
char enteredplayername[256];
switch case
Code:
switch (playername)
{
case 1:
cout << "The earth pony nods. \"Okay then Heavy Hooves, we need to get you sorted out, \n we're all grateful for what you did, but even with that kind of sacrifice, it's going to take us a while to trust you.\" \n Sacrifice? And then you remember... Oh no. No, no, no...\n 1: Your Horn \n 2: Your Wings \n 3: Your Leg (Earth Pony)\n\n";
break;
case 2:
cout << "The earth pony nods. \"Okay then Far Sighted, we need to get you sorted out, \n we're all grateful for what you did, but even with that kind of sacrifice, it's going to take us a while to trust you.\" \n Sacrifice? And then you remember... Oh no. No, no, no...\n 1: Your Horn \n 2: Your Wings \n 3: Your Leg (Earth Pony)\n\n";
break;
case 3:
cout << "The earth pony nods. \"Okay then Swift Tailed, we need to get you sorted out, \n we're all grateful for what you did, but even with that kind of sacrifice, it's going to take us a while to trust you.\" \n Sacrifice? And then you remember... Oh no. No, no, no...\n 1: Your Horn \n 2: Your Wings \n 3: Your Leg (Earth Pony)\n\n";
case 4:
//cout << "Type your character's first name: ";
//cin >> enteredfirstname;
//cout << "Type your character's last name: ";
//cin >> enteredlastname;
cout<<"Please enter your character's name: ";
cin.getline ( enteredplayername, 256, '\n' );
cout << "The earth pony nods Okay then " << enteredplayername << ", we need to get you sorted out, \n we're all grateful for what you did, but even with that kind of sacrifice, it's going to take us a while to trust you.\" \n Sacrifice? And then you remember... Oh no. No, no, no...\n 1: Your Horn \n 2: Your Wings \n 3: Your Leg (Earth Pony)\n\n";
break;
}
What I used is very close to the example program provided in the tutorial for entering long strings, and that worked fine when I ran it through the compiler, but when I try to run the program it doesn't let you enter anything for case 4 and skips right to printing out the next cout statement with a blank space where enteredplayername should be. I'm having trouble figuring out why and would be really grateful for the advice of more seasoned programmers.