I'm new to Coding and C++ is my first language, so I made this program which ciphers and deciphers the text after taking text(string) input from user, I want this program to be able to use multiple times in 1 run, so I made this recursive loop, program runs fine in first iteration , but in 2nd iteration it just skips the text input and moves forward
void cipherMain()
{
std::string text;
int selectOpt;
std::cout << "Enter Text" << std::endl;
getline(std::cin, text);
// std::cin >> text;
std::cout << "1.Cipher the text\n2.Decipher the text\n";
std::cout << "Select your option: ";
std::cin >> selectOpt;
std::string cipheredText;
std::string deCipheredText;
switch (selectOpt)
{
case 1:
cipheredText = cipher(text);
std::cout << "Ciphered text is:\n\"" << cipheredText << "\"\n";
system("pause");
break;
case 2:
deCipheredText = dCipher(text);
std::cout << "Deciphered text is:\n\"" << deCipheredText << "\"\n";
system("pause");
break;
default:
std::cout << "Invalid Input" << std::endl;
break;
}
char restart;
std::cout << "Enter 'y' to restart the program or 'n' to exit the program\n";
std::cin >> restart;
if(restart=='y')
{
system("cls");
cipherMain();
}
else
{
system("exit");
}
}
What I tried:
I replaced getline(std::cin,text)
with std::cin >> text;
this works, but I want my program to take whole line instead of just taking 1 word in input.
I want to get my getline(std::cin,text)
working