std::string digits[10] { "", "one", "two", "three" };
std::string teens[10] { "ten", "eleven", "twelve" };
if ( 0 < c ) std::cout << digits[c] << " hundred";
if ( 1 == b ) {
std::cout << ' ' << teens[a];
}
else {
// print tens with b
if ( 0 < a ) std::cout << ' ' << digits[a];
}
std::cout << '\n';
The digits is a lookup table that converts numeric index into text. Your switch statements are similar lookup tables, but which might be easier to get right?
It seems a lot easier using an array, but I have to use switch statements and if else statements.
I still can't get it right, I'm sure my condition statements are correct, if the middle integer = 0, and the last digit equals 0, print out "" which is essentially nothing.
if the middle integer is 1 and the last digit is 0, print out ten.