Yeah, I'm back with another question.
My code works like this: You write a message (heLLo), choose a key value (e.g. 3) and the result is khOOr (3 letters forward, with lower or upper case!).
The problem, is that if you write "Hello World" (with key value = 3), it will print "Khoor#Zruog". That means the space was considered in the code and was codified. I wanna ignore it, but maintaining he in the final.
Original code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
string msg_E;
char result_E, i;
int i;
for (i=0; i < msg_E.length(); i++) {
result_E = msg_E[i] + keyValue_E;
if (isupper(msg_E[i])) {
if (result_E > 90) result_E -= 26;
}
if (islower(msg_E[i])) {
if (result_E > 122) result_E -= 26;
}
cout << result_E;
}
I tried to restrict the ASCII characters, but it didn't work.
*In here, even if result_E = msg_E[i] + keyValue_E; is inside or before the If statements, the space continue being considered.
1 2 3 4 5 6 7 8 9 10 11 12
for (i=0; i < msg_E.length(); i++) {
result_E = msg_E[i] + keyValue_E;
if (msg_E[i] >= 65 && msg_E[i] <= 90) {
if (result_E > 90) result_E -= 26;
}
if (msg_E[i] >= 97 && msg_E[i] <= 122) {
if (result_E > 122) result_E -= 26;
cout << result_E;
}
And I tried to consider only alphabetic characters, but it suppress the space in the end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
for (i=0; i < msg_E.length(); i++) {
result_E = msg_E[i] + keyValue_E;
if (isalpha(msg_E[i])) {
if (isupper(msg_E[i])) {
if (result_E > 90) result_E -= 26;
}
if (islower(msg_E[i])) {
if (result_E > 122) result_E -= 26;
}
cout << result_E;
}
}
Sorry, I wasn't clear... :S
In the original code, if I enter "Hello World", it prints "Khoor#Zruog".
With the isspace, if I enter "Hello World", it prints "KhoorZruog".
I want it to prints "Khoor Zruog".