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 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <string>
#include "Numbers.h"
using namespace std;
void Numbers::print()
{
string lessThanTwenty[20] = { " ", "One", "Two", "Three", "Four", "Five" ,"Six", "Seven", "Eight",
"Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string tens[10] = { " ", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty" };
string hundreds = " Hundred";
string thousands = " Thousand";
// Residue holds what remains to be printed.
int residue = number;
// Take care of thousands, if any.
int n_thousands = residue / 1000;
residue = residue % 1000;
if (n_thousands > 0)
{
cout << lessThanTwenty[n_thousands];
cout << thousands;
}
// Fill the blank
// Take care of hundreds, if any.
int n_hundreds = residue / 100;
residue = residue % 100;
if (n_hundreds > 0)
{
cout << lessThanTwenty[n_hundreds];
cout << hundreds;
}
// Take care numbers less than a 100.
int n_tens = residue / 10;
residue = residue % 10;
if (n_tens > 0)
{
cout << " " << lessThanTwenty[n_tens];
}
// Take care of anything less than 20
int n_ones = residue / 1;
residue = residue % 1;
if (n_ones > 0)
{
cout << " " << lessThanTwenty[n_ones];
}
cout << endl;
}
|