View Single Post
Old 05-14-2004, 03:57 PM   #1 (permalink)
rarmknecht
Registered User
 
Join Date: May 2004
Location: US
Posts: 3
rarmknecht is on a distinguished road
Question Program is skipping cin.getline call

I'm not quite sure what is happening here, just that after much cutting of code I am still able to recreate the error and have narrowed it down to this section.

If I remove the part where it asks for encryption/decryption it allows user input. However, if it that portion is included, it skips over the cin.getline(input, MAXLN); call and displays all the cout's as if input was blank. Any ideas? I'm compiling under linux but you can feel free to compile it under windows. It really doesn't matter to me.

And the code:
Code:
#include <iostream>
using namespace std;

const int MAXLN = 128;
bool encrypted;

int main(int argc, char * argv[])
{

		char input[MAXLN];	//Holdind the string
		char temp;


		cout << "Press 1 to encrypt.  Press 2 to decrypt.\n";
		cin >> temp;

		if(temp == '2')	//Decryption needed
		{
			encrypted = true;
			cout << "Decryption it is then!" << endl;
		}
		else
		{
			if(temp == '1')
			{
				encrypted = false;
				cout << "Encryption is it then!" << endl;
			}
			else
			{
				cout << "You should have entered a number!" << endl;
				return 1;
			}
		}
	
		
		cout << "\nPlease enter in the text you would like to modify:" << endl;

		//grab the input string
		cin.getline(input, MAXLN);
		
		cout << "You entered: " << input << endl;
		
		return 0;
}
rarmknecht is offline   Reply With Quote