
Originally Posted by
Salem
Well it's a bit of a clue when you're doing this
> for (int i=10; i < 30; i++)
It does alright at the start
Ten
Eleven
Twelve
Thirteen
Fourteen
Fifteen
Sixteen
Seventeen
Eighteen
Nineteen
But then goes haywire
Twenty Two
Thirty Two
Forty Two
Fifty Two
Sixty Two
Seventy Two
Eighty Two
Ninety Two
It seems to me that all those "Two" should be "Twenty"
Check your / and %
I figured it out!
Code:
#include <iostream>
#include <string>
using namespace std;
string tens(int number);
string singles(int number);
string bigger_tens(int number);
int main()
{
/*cout << "Please type your number you wish to convert: ";
int number;
cin >> number; */
for (int i=0; i < 100; i++)
{
if (i < 10)
{
cout << singles(i) << endl;
}
else if (i >= 10 && i < 20)
{
cout << tens(i) << endl;
}
else if (i >= 20 && i < 100)
{
cout << bigger_tens(i) << endl;
}
}
return 0;
}
string singles(int number)
{
char *words[] =
{
"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"
};
return words[number%10];
}
string tens(int number)
{
char *words[] =
{
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"
};
return words[number%10];
}
string bigger_tens(int number)
{
char *words[] =
{
"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"
};
string first_word = words[number/10 - 2];
string second_word = singles(number%10);
if (second_word == "Zero")
{
return first_word;
}
else
{
string whole_word = first_word + "-" + second_word;
return whole_word;
}
}