C#コンソールアプリケーションを閉じようとしています(デバッグなしで実行しています)が、何も機能していません...さまざまな終了コードで通常の容疑者をすべて試しましたが、何も終了していません=/オプションがネストされた束にあるためですifステートメント?それはおそらく私が見逃している本当に単純なものですが、私の脳を傷つけているので、誰か助けてください!私はもう試した :
System.Environment.Exit(0);
System.Environment.Exit(1);
System.Environment.Exit(-1);
return;
Application.Exit(); //(wont even except it)
コンテキストが役立つ場合は、ネストされたifステートメントを使用して、ユーザーが数字を入力したか、文字「q」を入力したかを確認しました。数字を入力した場合は計算が実行され、文字qを入力した場合、プログラムは終了し、それ以外の場合は、エラーステートメントが出力されます。
string userInput;
int userInputDigit = 0;
double userCost = 0;
char userInputChar;
userInput = Convert.ToString(Console.ReadLine());
if (int.TryParse(userInput, out userInputDigit))
{
if (userInputDigit <= 50)
{
userCost = (price * userInputDigit);
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else if ((userInputDigit > 50) && (userInputDigit <= 80))
{
userCost = (price * 50) + ((userInputDigit - 50) * (price - 1));
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else if ((userInputDigit > 80) && (userInputDigit <= 100))
{
userCost = (price * 50) + (30 * (price - 1)) + ((userInputDigit - 80) * (price - 2.50));
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else
{
Console.WriteLine("Error! Please input a number between 0 and 100");
}
}
else if (char.TryParse(userInput, out userInputChar))
{
if ((userInput == "q") || (userInput == "Q"))
{
System.Environment.Exit(0);
}
else
{
Console.WriteLine("Incorrect Letter Inputted");
}
}
else
{
Console.WriteLine("Error! Please input a number or 'q' to quit");
}