我让它显示红利,这样人们就可以毫不费力地破译代码。它工作过一次,但后来我不知道我做了什么让它停止工作。它非常适用于正整数。它应该显示与用户输入相关的数字。
#include <iostream> // Necessary header
using namespace std;
int main()
{
signed int Input, Divisor, Dividend, MSD;
cout << "Input:";
cin >> Input;
Divisor = 1;
Dividend = Input;
if (Input < 0)
{
Dividend *= -1;
cout << "minus ";
}
cout << Dividend;
while (Dividend > 9)
{
Divisor = Divisor * 10;
Dividend = Dividend / 10;
}
while (Divisor != 0)
{
MSD = Input / Divisor;
switch (MSD)
{
case 0:
cout << "zero ";
break;
case 1:
cout << "one ";
break;
case 2:
cout << "two ";
break;
case 3:
cout << "three ";
break;
case 4:
cout << "four ";
break;
case 5:
cout << "five ";
break;
case 6:
cout << "six ";
break;
case 7:
cout << "seven ";
break;
case 8:
cout << "eight ";
break;
case 9:
cout << "nine ";
break;
}
Input = Input - (MSD * Divisor);
Divisor /= 10;
}
return 0;
}