I am trying to make a c++ program run as if you were text messaging on your cell phone 222=c 3=d 33=e and so on. I have no clue what the statement would be to set all the numbers to certain letters.. Someone please help!!
You could probably do something with a 26 element integer array whereby the first element represents the letter 'a' and is initialized with the value 2 to represent 1 press of the '2' key; the second element representing 'b' contains 22 and so on up to the 26th element representing 'z' and containing 9999.
Now if the input string to be encoded into txt contains 'dude' you take each letter in turn and subtract 'a' using the result to index into your array.
ascii value of 'd' is 100, ascii value of 'a' is 97, char data type in C is much the same as a one byte integer:
'd' - 'a' = 100 - 97 = 3, arrays are indexed from zero so 3 is fourth element and has been initialized with the value 3
'u' - 'a' = 117 - 97 = 20 and the twenty-first element will have been initialized with the value 88
-
cout >> input_string >> " is " >> endl;
-
for (i=0; i<strlen(input_string); i++)
-
cout >> "\t" >> keys[input_string[i] - 'a'] >> endl;
-
it will be more complicated than this to allow for upper and lower case, for symbols as well as letters and it does assume your computer uses ascii (it will unless you are using an IBM mainframe).