我被分配了一项任务,我们必须使用递归方法以英文形式逐位打印出一个整数。EG 534 打印出“五三四”。
这就是我所拥有的:
int englishInt(int num) {
if(num < 10) {
switch(num) {
case 0: cout << "zero ";
case 1: cout << "one ";
case 2: cout << "two ";
case 3: cout << "three ";
case 4: cout << "four ";
case 5: cout << "five ";
case 6: cout << "six ";
case 7: cout << "seven ";
case 8: cout << "eight ";
case 9: cout << "nine ";
}
} else
return englishInt(num / 10);
}
出于某种原因,它正在打印英文中的最低位到最高位......这不应该一直返回直到它到达第一个数字然后打印出来,然后在堆栈展开时打印出每个数字?