I'm wondering how I can go back to an alphabet letter I want that letter to land on?
Adding capital letters. Lower case letters not needed.
For example;
- User enters "XYZ"
- Program comes up with the next 10 letters which would be something like 'HIJ' (Since X+10 = H, Y+10 = I, Z+10=J)
My problem is with the last few letters. The program goes to the next 10 characters ahead of those characters rather then the alphabet.
Program example: (What I want shown)
"What are your three favorite letters?" XYZ
"The next ten letters are: HIJ"
Error example: {It goes to the next 10 characters instead of the next 10 alphabet letters.)
"What are your three favorite letters?" XYZ
"The next ten letters are: ^[a"
Code example: (I've tried other ways as well.)
1 2 3 4
char a, b, c;
cout << "What are your three favorite letters?";
cin >> a >> b >> c;
cout << "The next ten letters are: " << a+10 << b+10 << c+10 << endl;
You can examine to see if your addition has pushed the character passed 'Z'. And if it did, you can wrap back to the start by subtracting 26 (26 chars in the alphabet)
1 2 3 4
char foo = 'Y' + 10; // example input
if( foo > 'Z' ) // is it passed 'Z'?
foo -= 26; // yes? Then subtract 26 to make it wrap.