0
How do I pass integers to characters (in a string) in C++?
I need to get, for example, the numerical value for a name. Let's take a random name; Axel. (Taking a=1 , b=2, c=3, ... , z=26) The numerical value should be 1+24+5+12=42 (a+x+e+l) Anyone can help?
2 Answers
+ 8
I would do it like so:
Look into the ascii table.
http://www.asciitable.com/mobile/
Note the values that the uppercase or lowercase begins.
Decide if you want to convert the users input into uppercase or lower case.
Get the users input.
Traverse the string using a for loop
Subtract the starting number of the equivalent character set (upper or lower) from the characters ascii value plus 1 add this value to a running sum variable. Repeat as required until the string is complete.
+ 1
Thanks a lot. I've been able to write the code and it runs perfectly :D