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
|
#include <iostream>
#include <cstddef> // size_t is a typedef on an unsigned int
int main ( )
{
const char* strDigits_tens[] = { "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" } ;
const char* strDigits_ten[] = { "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" } ;
const char* strDigits_units[] = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" } ;
while(true) // debug
{
std::cout << "Number: " ;
std::size_t Number ;
std::cin >> Number ;
// Split the Number in two digits:
std::size_t Digits[2] ;
Digits[0] = Number/10 ; // example: 98 / 10 = 9
std::cout << "[DEBUG] " << Digits[0] << std::endl ;
if ( Digits[0] == 0 ) // if the Number isn't a tens. example: 9/10 = 0
{
Digits[1] = Number ;
std::cout << "It's: " << strDigits_units[Number-1] << std::endl ;
}
else
{
Digits[1] = Number-Digits[0]*10 ; // example: 98- (9*10) = 8
if ( Digits[0] == 1 ) // if the first digit is an 1. example: 12
if ( Digits[1] == 0 )
std::cout << "It's: " << strDigits_tens[Digits[1]] << std::endl ;
else
std::cout << "It's: " << strDigits_ten[Digits[1]-1] << std::endl ;
else if ( Digits[1] == 0 ) // if the second digit is a 0. example: 30
std::cout << "It's: " << strDigits_tens[Digits[0]-1] << std::endl ;
else
std::cout << "It's: " << strDigits_tens[Digits[0]-1] << "-" << strDigits_units[Digits[1]-1] << std::endl ;
}
}
return 0 ;
}
|