この質問は以前に投稿され、回答されていますが。コードのヘルプが必要でした。タスクは、0 から 1000 万までの数字を単語に変換することです。GUIを使用して自分のコードでそれをやろうとしましたが、問題は答えがまったく返されないことです。コードの問題が何であるかを特定するのを手伝ってくれる人はいますか。
以下のコード:
private void btnConvertToText_Click(object sender, EventArgs e)
{
string ConvertedNumber = " ";
int number = Convert.ToInt32(txtNumber.Text);
int Count = 0;
string [] ones = {" One ", " Two ", " Three ", " Four ", " Five ", " Six ", " Seven ", " Eight ", " Nine "};
string [] teens= {" Eleven ", " Twelve ", " Thirteen ", " Fourtte n ", " Fifteen ", " Sixteen ", " Seventeen ", " Eighteen ", " Nineteen "};
string [] tens = {" Ten ", " Twenty ", " Thirty ", " Fourty ", " Fifty ", " Sixty ", " Seventy ", " Eighty ", " Ninenty "};
string [] moreThenTens = {" hundred ", " thousand ", " million "};
while (number >= 0)
{
if (number == 0)
{
ConvertedNumber = "Zero";
}
else if (number < 10)
{
for (int Counter = 1; Counter < 10; Counter++)
{
ConvertedNumber += ones[Counter-1];
}
}
else if (number >= 10 && number < 100)
{
while (number > 10)
{
if (number > 10 && number < 20)
{
for (int x = 11; x < 20; x++)
{
if (number == x)
{
ConvertedNumber = teens[x - 11];
}
}
}
else
{
number -= 10;
Count++;
}
ConvertedNumber += tens[Count - 1];
}
}
else if (number >= 100 && number < 1000)
{
while (number > 100)
{
number -= 100;
Count++;
}
ConvertedNumber += ones[Count - 1] + moreThenTens[0];
}
else if (number >= 1000 && number < 10000)
{
while (number > 1000)
{
number -= 1000;
Count++;
}
ConvertedNumber += ones[Count - 1] + moreThenTens[1];
}
else if (number >= 10000 && number < 100000)
{
while (number > 10000)
{
if (number < 20000)
{
number -= 10000;
Count++;
}
else if (number >= 20000)
{
number -= 10000;
Count++;
}
}
if (Count >= 1)
{
if (number < 1000)
{
ConvertedNumber += tens[0] + moreThenTens[1];
}
else if (number >= 1000)
{
ConvertedNumber += teens[Count - 1] + moreThenTens[1];
}
}
else if (Count > 1)
{
ConvertedNumber += tens[Count - 1] + moreThenTens[1];
}
}
else if (number >= 100000 && number < 1000000)
{
while (number > 100000)
{
number -= 100000;
Count++;
}
ConvertedNumber += ones[Count - 1] + moreThenTens[0] + moreThenTens[1];
}
else if (number >= 1000000 && number < 10000000)
{
while (number > 1000000)
{
number -= 1000000;
Count++;
}
ConvertedNumber += ones[Count - 1] + moreThenTens[2];
}
else if (number == 10000000)
{
while (number > 10000000)
{
number -= 10000000;
Count++;
}
ConvertedNumber += tens[0] + moreThenTens[2];
}
}
txtConvertedNumber.Text = ConvertedNumber;
}
}