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
|
#include <iostream>
#include <string>
const std::string ones[] {"", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine"
};
const std::string tens[] {"", "ten", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety",
"one hundred" /*slight cheating*/
};
const std::string special[] {"", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"
};
int main()
{
int num;
std:: cout<< "Input a value from 1-100: ";
std::cin >> num;
while (num<=0 || num>100) {
std::cout << "ONLY INPUT A VALUE RANGING FROM 1-100!!!\n";
std::cin >> num;
}
std::string name;
if(10 < num && num < 20) {
name = special[num % 10];
} else {
name = tens[num/10];
if(num/10 && num%10)
name += '-';
name += ones[num % 10];
}
std::cout << "The number you've entered is: " << name;
}
|