My problem is that this function returns guess as the sum of 97 and y, instead of just the letter, as the switch statement is instructing it to. The weird thing is, when I have it just return y, it is working exactly as I would expect it to. For example, when y=4, and i have it return y, 4 is displayed. When y=4 and ‘guess’ is returned, 101 is displayed. Disclaimer: this is not the full code. It’s really long, and I think superfluous, as the only problem I have is when this specific function returns ‘guess’, not even when it returns y. If all the code would be useful though, i would be happy to put it up.
int letterguess(int z){
char guess;
int y;
y=letters[0][z];
switch (y){
case 0:
guess='a';
break;
case 1:
guess='b';
break;
case 2:
guess='c';
break;
case 3:
guess='d';
break;
case 4:
guess='e';
break;
case 5:
guess='f';
break;
case 6:
guess='g';
break;
case 7:
guess='h';
break;
case 8:
guess='i';
break;
case 9:
guess='j';
break;
case 10:
guess='k';
break;
case 11:
guess='l';
break;
case 12:
guess='m';
break;
case 13:
guess='n';
break;
case 14:
guess='o';
break;
case 15:
guess='p';
break;
case 16:
guess='q';
break;
case 17:
guess='r';
break;
case 18:
guess='s';
break;
case 19:
guess='t';
break;
case 20:
guess='u';
break;
case 21:
guess='v';
break;
case 22:
guess='w';
break;
case 23:
guess='y';
break;
case 24:
guess='y';
break;
case 25:
guess='z';
break;
}
return guess;
}
I really cannot see how this possibly could get messed up like this. Thanks in advance.
Change this:
to this:
Then when you output the return value you’ll get the letter instead of its numerical value.