每當我爲分母輸入一個無效的數字(例如數字太長或字母)時,我總是會得到「NOtZero」。我的If/Else語句邏輯不正確。什麼是錯的,我該如何解決這個問題?Else block not working
static void Main(string[] args)
{
Console.WriteLine("Enter Numerator");
int numerator;
bool IsNumeratorConverstionSucess=Int32.TryParse(Console.ReadLine(), out numerator);
if (IsNumeratorConverstionSucess)
{
Console.WriteLine("Enter Denominator");
int denominator;
bool IsdenominatorConverstionSucess = Int32.TryParse(Console.ReadLine(), out denominator);
if (IsdenominatorConverstionSucess && denominator != 0)
{
int result = numerator/denominator;
Console.WriteLine("Result is = {0}", result);
}
else
{
if(denominator==0)
{
Console.WriteLine("NOtZero");
}
else
{
Console.WriteLine("Deominator Should Be A Valid Number Between {0} To {1} Range", Int32.MinValue, Int32.MaxValue);
}
}
}
else
{
Console.WriteLine("Numerator Should Be A Valid Number Between {0} To {1} Range",Int32.MinValue,Int32.MaxValue);
}
}
它真的*不清楚你想達到什麼。我假設英語不是你的母語 - 這當然是好事,但確實使我們難以幫助你。我建議你問一個有更好英語指導的朋友或同事,以幫助你解釋你想要做什麼和出現什麼問題。 –
好的感謝您的建議 –