Activity 7 - Input line

Congratulations!

You are very close to completely saving the nation. All that remains is to be able to enter a complete sentence! For this we only have to make a few small changes. First, you need to use the statement to enter the string:getline().

string phrase;
getline(cin, phrase);

By doing it this way, the console will be able to accept a complete message, not just a single word.

Follow these steps, and complete the program to save the kingdom:

  1. In the main function, change the statement cin >> name; to getline(cin, name);.
  2. In both functions, add an if condition in the for loop, and execute the contents of the for loop only if the current character is greater than or equal ‘>=’ to the character ‘a’ and less than or equal ‘<=’ to the character ‘z’. By doing so, we can ignore encrypting and decrypting exclamation points, commas, spaces, and other special characters.

Don’t forget how this program works:

  1. First, the program asks for the user’s name.
  2. Next, we must decide if the message must be encrypted or decrypted by typing 1 (for encryption) or 2 (for decryption).
  3. Finally, we type in the message to encrypt or decrypt.

Create your own secret messages, or decrypt those of your peers!

Remember that you can always go back to the previous activities to review anything!