If you wanted to give a value to each letter of the alphabet, how would you? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If you wanted to give a value to each letter of the alphabet, how would you?

Aside from labeling each individual letter to a value, is there an easier way to do this?

4th Nov 2018, 5:31 PM
JDLives
2 Answers
+ 2
Easy char[] = "abcdefghijklmnopqrstuvwxyz"; Use the respective index as a value. Like char[0] equals a other solution: You can loop using chars. just start in 'a' and checks if letter <= 'z' and incremment letter if not. Use this to give any value that you want
4th Nov 2018, 5:54 PM
Anya
Anya - avatar
+ 1
for (char c = 'a'; c <= 'z'; c++) std::cout << c << ", "; you can just increment characters
4th Nov 2018, 6:09 PM
Jordan Chapman
Jordan Chapman - avatar