k is an int between 0 and 25 (letters of the alphabet).
What I'm doing is a letter shift. A=0, B=1, C=2, etc. If k is 0, message[i] remains the same. if k is 1, message[i] is moved from letter 1 (lets say A) to letter 2 (B).Code:in a for loop that increments i int temp = message[i]; temp = temp+k; message[i] = temp;
Here is a hypothetical situation to illustrate my problem:
k = 25
message[i] = Z
ASCII value of 90 + 25 = 115, a lower case "s".
What I'd do is print out all Upper case letters. So if message[i] reaches 90 it returns back to 65 (A) and increments from there. (In this example that would result in Z translating to 85, the letter U).
Any ideas?![]()



LinkBack URL
About LinkBacks





A 'char' is just an int that holds values from -128 to 127, and you can do +1 -1 etc. as you would to any other integral datatype.