Oct 10, 2013 at 9:27pm UTC
How will you know if it worked if there is no output?
Oct 10, 2013 at 9:30pm UTC
right now it reads the input from the user then after hitting return it prints out the same thing. i'm trying to find a way to make it read everything up until the user enters a blank line.
Oct 10, 2013 at 10:08pm UTC
This works for normal input/output but the reason I'm using int c is because I'm planning on shifting the letters forward by 5.
Oct 10, 2013 at 10:14pm UTC
What are you trying to create, a Caesar cipher?
Oct 10, 2013 at 10:17pm UTC
Yes. I'm using cout.put() to print the result.
Oct 10, 2013 at 10:31pm UTC
The code I gave you does not need to be changed too much:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <string>
int main()
{
std::string input;
std::getline(std::cin, input);
while (input != "" )
{
for (int i = 0; i < input.length(); i++)
{
if (input[i] >= 'a' && input[i] <= 'z' )
{
input[i] = (input[i] - 'a' + 5) % ('z' - 'a' + 1) + 'a' ;
}
if (input[i] >= 'A' && input[i] <= 'Z' )
{
input[i] = (input[i] - 'A' + 5) % ('Z' - 'A' + 1) + 'A' ;
}
}
std::cout << input << std::endl;
std::getline(std::cin, input);
}
return 0;
}
This program will only shift the letters a - z and A - Z.
Last edited on Oct 10, 2013 at 10:45pm UTC
Oct 10, 2013 at 10:44pm UTC
I just made a change in lines 16 and 20.