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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
int num, Ldight, Rdight, Hdight;
string ones[] = {"zero", "one", "two", "three", "four",
"five","six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"};
string tens[] = {"twenty","thirty","fourty","fifty", "sixty","seventy","eighty", "ninety"};
string hundreds[] = {"one hundred", " two hundred", "three hundred", "four hundred", "five hundred", "six hundred", "seven hundred", "eight", "nine hundred"};
cout << "Pick a number between 0-999: ";
cin >> num;
if(num <= 0)
{
cout << "Try again!" << endl;
}
else if (num >= 0 && num <= 19)
{
cout << "Your number is: " << ones[Rdight] ;
}
else if (num >=20 && num <=99)
{
Rdight = num % 10;
Ldight = num / 10;
cout << "Your number is: " << tens[Ldight - 2] << ones[Rdight];
}
else if (num >=99 && num <=999)
{
Rdight = num % 10;
Ldight = num / 10;
Hdight = num / 100;
num = num - Hdight * 100;
cout << "Your number is: " << hundreds[Hdight-1] << tens[Ldight - 2] << ones[Rdight];
}
return 0;
}
|