Hello again.
For the current lab, we're working with strings and pointers. I'm trying to keep this one simple and get one step working right before I move on to the next. However, if I have subsequent issues with this lab, I'll just use this same thread rather and make more.
In the first part of this lab we are to have the user input a last name, first name, and middle name. That input needs to be put into an array as a string. This fixed array will be used later on for pointer and DMA play.
The code I have written for this first part compiles, and runs, but it skips the input for the last name.
Allow me to show you what I mean:
//=============================================================================
#include <iostream> // for cin,cout
#include <cstring> // for string manipulation
using namespace std;
//=============================================================================
// CONSTANT DEFINITIONS
// none
//=============================================================================
// EXTERNAL CLASS VARIABLES
// none
//=============================================================================
//*****************************************************************************
// BEGINNING OF PROGRAMMING CODE
//****************************************************************************
int main()
{
// declare local constant(s), variable(s), and array(s)
char LName[32];
char FName[16];
char MName[16];
int go;
cout << "Enter 1 to Continue 0 to Quit" << endl;
cin >> go;
// loop to get things going
if (go > 0)
{
cout << "\n\nEnter Last Name\n\n";
cin.getline ( LName, 32, '\n');
cout << "\n\nEnter First Name\n\n";
cin.getline ( FName, 16, '\n');
cout << "\n\nEnter Middle Name\n\n";
cin.getline ( MName, 16, '\n');
// bring it all together
cout << "Hello " << FName << " " << MName << " " << LName << " >*^.^*< " <<endl;
// do it again
cout << "Enter 1 to Continue 0 to Quit" << endl;
cin >> go;
}
else
return 0;
}
/*
O U T P U T
Enter 1 to Continue 0 to Quit
1
Enter Last Name
Enter First Name
Bob
Enter Middle Name
David
Hello Bob David >*^.^*<
Enter 1 to Continue 0 to Quit
*/
What is making it automatically skip the first input?