Hello, everyone I am pretty much a new programmer programming a little in C++ and
basic. I am having trouble with this portion of the program that I am working on.
When I include line 16, cin >>FullTimePartTime;
the program skips line 21, cin.getline(response,256);
and does not let me enter anything for the response variable.
But when I comment or delete out line 21 the program does fall through to the
else command and prints out what was entered in the response variable.

For you experinced C++ programmers, I need to know
1) why is this skipping line 21 with line 16 included and

2) I really don't need to include the cin >>FullTimePartTIme statement, how can I
get the program to work without inluding this statement.

3) I'm trying to write my program and this is bogging me down, as I have spent the
last 3 or 4 days( a couple hours each day ) trying to fix the problem. Do you
guys think I am spending to much time on one problem or should I continue with the
program so I can write another one.

__________________________________________________________________________________

#include <iostream>
#include <string>

using namespace std;

int main()
{
  char key;
  using namespace std;
  string FullTimePartTime; 

  char response[256];

  cout << "\n\nDO YOU NEED TO CALCULATE FULLTIME OR PARTIME EXPENSES? ";   
  cin >>FullTimePartTime;         //cin is placed here program skips 
                                         //cin.getline(response,256)

  cout << endl;                   
  cout << "What is your name? ";  //
  cin.getline(response,256);

  if (strlen(response) == 0)
    cout << "\nYou must tell me your name...";
  else
    cout << "It's nice to meet you, " << response;
    cout << "\ntype a key and hit return ";
    cin >> key;
  return 0;
}

Edited 3 Years Ago by Dani: Formatting fixed

Greetings.
Err, I don't really get what you mean.

2) I really don't need to include the cin >>FullTimePartTIme statement, how can I
get the program to work without inluding this statement.

When I take those lines out, it worked just fine, as in, I could enter a name and get it displayed in return ;)

#include <iostream>
#include <string>

using namespace std;

int main()
{
char key;
using namespace std;
char FullTimePartTime;

char response[256];

//cout << "\n\nDO YOU NEED TO CALCULATE FULLTIME OR PARTIME EXPENSES? ";
//cin >>FullTimePartTime; 
//cin is placed here program skips
//cin.getline(response,256)

cout << endl;
cout << "What is your name? "; //
cin.getline(response,256);

if (strlen(response) == 0)
cout << "\nYou must tell me your name...";
else
cout << "It's nice to meet you, " << response;
cout << "\ntype a key and hit return ";
getchar();
return 0;
}

Greetings.
Err, I don't really get what you mean.

When I take those lines out, it worked just fine, as in, I could enter a name and get it displayed in return ;)

#include <iostream>
#include <string>

using namespace std;

int main()
{
char key;
using namespace std;
char FullTimePartTime;

char response[256];

//cout << "\n\nDO YOU NEED TO CALCULATE FULLTIME OR PARTIME EXPENSES? ";
//cin >>FullTimePartTime; 
//cin is placed here program skips
//cin.getline(response,256)

cout << endl;
cout << "What is your name? "; //
cin.getline(response,256);

if (strlen(response) == 0)
cout << "\nYou must tell me your name...";
else
cout << "It's nice to meet you, " << response;
cout << "\ntype a key and hit return ";
getchar();
return 0;
}

you need a semicolon on line 17 and heres a little better version of your code

#include <iostream>
#include <string>

using namespace std;

int main()
{
char key;
using namespace std;
char FullTimePartTime;

char response[256];

cout << "What is your name? "; //
cin.getline(response,256);

if(strlen(response) == 0)
{
cout << "\nYou must tell me your name...";
return main();
}

cout << "It's nice to meet you, " << response;
cout << "\ntype a key and hit return ";
getchar();
return 0;
}

Greetings.
Umm, refering to the first post, I'd like to make some ammendments.
If you'd like to let's say maintain cin>>FullTimePartTime;
just before a cin.getline(...), you should clear your input buffer first.
Use fflush(stdin); to do that, and your cin.getline will not skip.

#include <iostream>
#include <string>

using namespace std;

int main()
{
char key;
using namespace std;
char FullTimePartTime;

char response[256];

cout << "\n\nDO YOU NEED TO CALCULATE FULLTIME OR PARTIME EXPENSES? ";
cin >>FullTimePartTime; 
fflush(stdin);
cout << endl;
cout << "What is your name? ";
cin.getline(response,256);

if (strlen(response) == 0)
cout << "\nYou must tell me your name...";
else
cout << "It's nice to meet you, " << response;
cout << "\ntype a key and hit return ";
getchar();
return 0;
}

Hope it helps.

Greetings.
Sorry if I was wrong. ;)
steerles_fan, sorry for giving the wrong advice.
Dave, maybe you could advise steerles_fan on this?

This article has been dead for over six months. Start a new discussion instead.