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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <string>
using namespace std;
/////////Implement the source code that turns numbers into English text.
int main()
{
int num, Ldight, Rdight, Tdight, Fdigit;
string ones[] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen"};
string tens[] = { "", "", "twenty ", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninghty"};
string hundreds[] = { "", "one hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"};
string thousand[] = { "thousand"}; ///incomplete
cout << "Enter a number from 1-1000: " << endl;
cin >> num;
if(num <= 19 && num >= 1)
{
Rdight = num %10;
Ldight = num/10;
cout << "The number you entered is: " << ones[num] << endl;
}else if(num >= 20 && num <= 99)
{
Rdight = num %10;
Ldight = num/10;
cout << "The number you selected is: " << tens[Ldight] << ones[Rdight] << endl;
}else if( num >=100 && num <= 119)
{
Rdight = num%50;
Tdight = num/100;
cout << "The number you selects is: " << hundreds[Tdight] << ones[Rdight] << endl;
}else if( num >=120 && num <= 999)
{
if( num%50 == 19)//////219,319,419,519,619
{
Rdight = num%50;
Tdight = num/100;
cout << "The number you selects is: " << hundreds[Tdight] << ones[Rdight] << endl;
}else
{
Rdight = num %10;
Ldight = (num%100)/10;
Tdight = num/100;
cout << "The number you selects is: " << hundreds[Tdight] << tens[Ldight] << ones[Rdight] << endl;
}
}
system("pause");
}
|