Skip to main content
added 126 characters in body
Source Link
kocica
  • 6.5k
  • 2
  • 17
  • 37

Its int array so it means that it will save ASCII values of characters.

If you would look carefully on ASCII table, you would find out that 48,49,50,... are ascii values of numbers 0,1,2,...

What you have to do is deduct value of first number in table -> '0' (48)

cout << numbers[checkedAlpha] - '0' << "-"; 

or better, save numbers as numbers not characters

 int numbers [27] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14​,15,16,17,18'​,19,20,21,22,23,24,25,26​,0 }; 

Btw. here is hint which make it easier for you

tolower(inputAlphabet[index]) - 'a' + 1 // For 'a' output is 1 and so on :-) 

Its int array so it means that it will save ASCII values of characters.

If you would look carefully on ASCII table, you would find out that 48,49,50,... are ascii values of numbers 0,1,2,...

What you have to do is deduct value of first number in table -> '0' (48)

cout << numbers[checkedAlpha] - '0' << "-"; 

or better, save numbers as numbers not characters

 int numbers [27] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14​,15,16,17,18'​,19,20,21,22,23,24,25,26​,0 }; 

Its int array so it means that it will save ASCII values of characters.

If you would look carefully on ASCII table, you would find out that 48,49,50,... are ascii values of numbers 0,1,2,...

What you have to do is deduct value of first number in table -> '0' (48)

cout << numbers[checkedAlpha] - '0' << "-"; 

or better, save numbers as numbers not characters

 int numbers [27] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14​,15,16,17,18'​,19,20,21,22,23,24,25,26​,0 }; 

Btw. here is hint which make it easier for you

tolower(inputAlphabet[index]) - 'a' + 1 // For 'a' output is 1 and so on :-) 
Source Link
kocica
  • 6.5k
  • 2
  • 17
  • 37

Its int array so it means that it will save ASCII values of characters.

If you would look carefully on ASCII table, you would find out that 48,49,50,... are ascii values of numbers 0,1,2,...

What you have to do is deduct value of first number in table -> '0' (48)

cout << numbers[checkedAlpha] - '0' << "-"; 

or better, save numbers as numbers not characters

 int numbers [27] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14​,15,16,17,18'​,19,20,21,22,23,24,25,26​,0 };