Activity 7 - Input line
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 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:
- In the
mainfunction, change the statement
cin >> name;to
- In both functions, add an
ifcondition in the
forloop, and execute the contents of the
forloop 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:
- First, the program asks for the user’s name.
- Next, we must decide if the message must be encrypted or decrypted by typing
1(for encryption) or
- 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!