#include void say(const int n); // that was a "prototype", a promise that a function exactly like that // will be defined before the end of the program. It lets us decide // what order things appear in, so we can put the important things // first and save the mere details until later void main() { while (true) { print("number? "); const int x = read_int(); say(x); new_line(); } } const string small_names[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; const string ty_names[] = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; void say(const int n) { if (n < 0) { print("minus "); say(- n); } else if (n < 20) print(small_names[n]); // everything before this point guaranteed good. // if n < 20, say(n) WILL WORK CORRECTLY. else if (n < 100 && n%10 == 0) print(ty_names[n / 10]); else if (n < 100) { say(n / 10 * 10); print("-"); say(n % 10); } // everything before this point guaranteed good. // if n < 100, say(n) WILL WORK CORRECTLY. else if (n < 1000) { say(n / 100); print(" hundred"); const int last_two = n % 100; if (last_two != 0) { print(" and "); say(last_two); } } // everything before this point guaranteed good. // if n < 1,000, say(n) WILL WORK CORRECTLY. else if (n < 1000000) { say(n / 1000); print(" thousand"); const int last_three = n % 1000; if (last_three != 0) { if (last_three < 100) print(" and "); say(last_three); } } // everything before this point guaranteed good. // if n < 1,000,000, say(n) WILL WORK CORRECTLY. else print("I can't do it\n"); }