#include "library.h" const string Small[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; const string tynumber[] = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; void say(const int n) { if (n < 0) { cout << "minus "; say(- n); } else if (n < 20) cout << Small[n]; else if (n%10 == 0 && n<100) cout << tynumber[n/10 - 2]; else if (n >= 20 && n < 100) { const int first = n /10 * 10, second = n % 10; say(first); cout << "-"; say(second); } else if (n < 1000) { const int first = n / 100; const int second = n % 100; say(first); cout << " hundred"; if (second > 0) { cout << " and "; say(second); } } else if (n < 1000000) { const int first = n / 1000; const int second = n % 1000; say(first); cout << " thousand"; if (second > 0) { cout << " "; say(second); } } else if (n < 1000000000) { const int first = n / 1000000; const int second = n % 1000000; say(first); cout << " million"; if (second > 0) { cout << " "; say(second); } } else { const int first = n / 1000000000; const int second = n % 1000000000; say(first); cout << " billion"; if (second > 0) { cout << " "; say(second); } } } bool want_to_go_again() { while (true) { cout << "Do you want to go again? "; const string s = read_string(); if (s == "yes") return true; if (s == "no") return false; } } void main() { while (true) { print("Enter a number: "); const int n = read_int(); say(n); new_line(); if (! want_to_go_again()) break; } cout << "End of program\n"; }