我正在編寫一個C++控制檯應用程序,並將a
轉換爲1
,b
轉換爲2
等。事情是,它像48和52輸出的數字 - 即使我立足其關閉陣列只上升到26數組輸出不正確 - C++
下面的代碼:
void calculateOutput() {
while (input[checkedNum] != alphabet[checkedAlpha]) {
checkedAlpha++;
if (checkedAlpha > 27) {
checkedAlpha = 0;
}
}
if (input[checkedNum] == alphabet[checkedAlpha]) {
cout << numbers[checkedAlpha] << "-";
checkedAlpha = 0;
checkedNum++;
calculateOutput();
}
}
這是我的數字和字母排列:
char alphabet [27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','o','p','q','r','s','t','u','v','w','x','y','z',' '};
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' };
如何定義「輸入」,「字母」和「數字」? – CinCout
提示:'inputAlphabet - 'a'+ 1'會給你所需要的 – CinCout
'numbers'數組來自哪裏?無論如何,你的輸出(像48等等)聽起來像[ASCII值](https://www.programiz.com/cpp-programming/examples/ASCII-value-character)。 – nondestructive