int total = 0;
int wordCount = 0, index = 0;
var vowels = new HashSet<char> { 'a', 'e', 'i', 'o', 'u' };
var consonants = new HashSet<char> { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x' };
for (int i = 0; i < sentence.Length; i++)
if (vowels.Contains(sentence[i]))
{
total++;
}
else if (consonants.Contains(sentence[i]))
{
total++;
}
}
Console.WriteLine("Your total number of vowels is: {0}", total);
Console.WriteLine("Number of consonants: {0}", total);
Console.ReadLine();
`
これは私のコードです。コードを実行すると、母音の数が正確にわかりますが、子音の数はわかりません。母音の数だけをコピーしました。文字列の母音と子音を数えます。
これは、あなたが尋ねた2回目のことであり、同じ 'total'変数を出力するのとまったく同じコードを持っていました。あなたの子音と母音を別の変数で数えます。 –
だから、 'total'は、母音の数と子音の数は?それはどのように機能するのですか? – John3136
はJohn3136 @、私は私のコードを実行すると、自分のコードが... **、それは正確にあるどのように多くの母音を私に伝えます(または理解しようとした)読んでいないオペアンプのように見えますが、それは私の子音の数を教えてくれありません。 ** –