I'm trying to create a function that will set a variable like so:
'a' would set the variable to 1.
'b' would set the variable to 2.
'c' would set the variable to 3.
I'm sure there's probably a correct term for this, share?
I temporarily named the variable 'sendBack'.
When I run this code, I always get the default in return.
#include "stdafx.h"
#include <iostream>
usingnamespace std;
void intro (void)
{
cout << "Enter your message: " << endl;
} // asks for a user to enter a message
int messageConverter (char letter)
{
int sendBack = -2;
switch (letter)
{
case'a':{
sendBack = 1; break;} // a to 1 to identify
case'b':{
sendBack = 2; break;} // b to 2 to identify
case'c':{
sendBack = 3; break;} // c to 3 to identify
case'd':{
sendBack = 4; break;} // d to 4 to identify
case'e':{
sendBack = 5; break;} // e to 5 to identify
case'f':{
sendBack = 6; break;} // f to 6 to identify
case'g':{
sendBack = 7; break;} // g to 7 to identify
case'h':{
sendBack = 8; break;} // h to 8 to identify
case'i':{
sendBack = 9; break;} // i to 9 to identify
case'j':{
sendBack = 10; break;} // j to 10 to identify
case'k':{
sendBack = 11; break;} // k to 11 to identify
case'l':{
sendBack = 12; break;} // l to 12 to identify
case'm':{
sendBack = 13; break;} // m to 13 to identify
case'n':{
sendBack = 14; break;} // n to 14 to identify
case'o':{
sendBack = 15; break;} // o to 15 to identify
case'p':{
sendBack = 16; break;} // p to 16 to identify
case'q':{
sendBack = 17; break;} // q to 17 to identify
case'r':{
sendBack = 18; break;} // r to 18 to identify
case's':{
sendBack = 19; break;} // s to 19 to identify
case't':{
sendBack = 20; break;} // t to 20 to identify
case'u':{
sendBack = 21; break;} // u to 21 to identify
case'v':{
sendBack = 22; break;} // v to 22 to identify
case'w':{
sendBack = 23; break;} // w to 23 to identify
case'x':{
sendBack = 24; break;} // x to 24 to identify
case'y':{
sendBack = 25; break;} // y to 25 to identify
case'z':{
sendBack = 26; break;} // z to 26 to identify
default:{
sendBack = -3; break;}
}
return sendBack;
}
int main()
{
intro();
int message;
cin >> message;
cout << messageConverter(message);
return 0;
}