I have rewritten it from scratch so that it is easier to spot mistakes. However, I get the exact same result and this time I'm pretty sure there is no possible mistake as the output seems correct to me. Here's the new code:
Code:
#include <iostream>
#include <string>
int main()
{
std::string thousand = "thousand";
std::string hundreds[] = {"hundred", "hundredand"};
std::string tens[] = {"ten", "twenty", "thirty", "fourty", "fifty",
"sixty", "seventy", "eighty", "ninety"};
std::string eton[] = {"eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
std::string units[] = {"one", "two", "three", "four", "five", "six",
"seven", "eight", "nine"};
int total = 0;
std::string tmp = "";
for(int i = 1; i < 2009; i++)
{
tmp = "";
if(i / 1000)
{
if((i/1000)%10 == 1) tmp += units[0];
else tmp += units[1];
tmp += thousand;
}
if(i / 100 && ((i/100)%10))
{
tmp += units[((i/100) % 10)-1];
if(i%100) tmp += hundreds[1];
else tmp += hundreds[0];
}
if(i / 10 && ((i/10) %10))
{
if((i % 100) <= 10 || (i % 100) >= 20)
tmp += tens[((i / 10) % 10)-1];
else
tmp += eton[(i%10)-1];
}
if(i % 10 && ((i % 100) <= 10 || (i % 100) >= 20))
tmp += units[(i%10)-1];
total += tmp.size();
std::cout << tmp << " : " << tmp.size() << "\n";
}
std::cout << std::endl << total;
}
And I have posted the output on here because it is pretty large.