Nov 15, 2016 at 9:30am UTC
Hello! I'm making a program that read Caesar Cipher. Everything works fine, but the program stops if it goes to the next line.
Here is my code so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string word;
getline(cin,word);
for (int i = 0; i <= word.length(); i++) {
if (word[i] >= 'M' && word[i] <= 'Z') {
word[i] = word[i] - 12;
}
else if (word[i] >= 'A' && word[i] <= 'L') {
word[i] = word[i] + 14;
}
else if (word[i] >= 'm' && word[i] <= 'z') {
word[i] = word[i] - 12;
}
else if (word[i] >= 'a' && word[i] <= 'l') {
word[i] = word[i] + 14;
}
else if (word[i] >= '0' && word[i] <= '9') {
word[i] = word[i];
}
else if (word[i] == ',' || word[i] == '.' || word[i] == ':') {
word[i] = word[i];
}
}
cout << word;
getchar();
getchar();
return 0;
}
For example, if I enter
Sqadsum
Ngffaz Siuzzqff, Xkymz Tmxx, Sqadsq Imxfaz
It stops at: Georgia
Any suggestions?
Nov 15, 2016 at 9:48am UTC
It works! Thank you.
However, is there anyway that I can output the same format with the input. I've tested the program and I have to press enter when move to another line?