How can I convert a character into an integer value? For example, I've been trying to read "A" as 1, "B" as 2, and so forth. I tried comparing the character to each letter in the alphabet and return the appropriate value.
int intvalue(char letter)
{
if(letter == "A")
return 1;
else if(letter == "B")
return 2;
else if(letter == "C")
return 3;
else if(letter == "D")
return 4;
else if(letter == "E")
return 5;
else if(letter == "F")
return 6;
else if(letter == "G")
return 7;
else if(letter == "H")
return 8;
else if(letter == "I")
return 9;
else if(letter == "J")
return 10;
else if(letter == "K")
return 11;
else if(letter == "L")
return 12;
else if(letter == "M")
return 13;
else if(letter == "N")
return 14;
else if(letter == "O")
return 15;
else if(letter == "P")
return 16;
else if(letter == "Q")
return 17;
else if(letter == "R")
return 18;
else if(letter == "S")
return 19;
else if(letter == "T")
return 20;
else if(letter == "U")
return 21;
else if(letter == "V")
return 22;
else if(letter == "W")
return 23;
else if(letter == "X")
return 24;
else if(letter == "Y")
return 25;
else if(letter == "Z")
return 26;
}
I got "error: ISO C++ forbids comparison between pointer and integer". Does anyone know how to fix this? Or even better, a different way to go about this? I feel like my above function is very brute-forceish.