You need only one of the if
statements to execute, so make sure you have the second two in else
clauses:
if(x==32) // keep spaces
{
cryptStr = cryptStr + (char)x;
}
else if((x>=65) && (x<=77)) // rotate 'A' through 'M' by +13
{
x=x+13;
cryptStr = cryptStr + (char)x;
}
else if((x>77) && (x<=90)) // rotate 'N' through 'Z' by -26+13=-13
{
x=x-13;
cryptStr = cryptStr + (char)x;
}
The way you have it now, if the 2nd if
gets executed then x
is incremented by 13 which makes the 3rd if's condition evaluate to true.