以下では、スイッチケース「c」内のコードは実行されません。何も起こりません!入力が「q」の場合、isOwner = falseは正常に実行されます。これは私には意味がありません。助けてください!シンプルスイッチケース内のコードまたはif文が実行されない
// Customer information
string customerName = "";
string customerPassword = "";
int customerCredits = 0;
string input = "";
Console.WriteLine ("Welcome to my console Pet Store");
Console.WriteLine ("Type in your name?");
customerName = Console.ReadLine();
Console.WriteLine ("Type in your password?");
customerPassword = Console.ReadLine();
if (customerName == "owner" && customerPassword == "1234") {
bool isOwner = true; // Launch the owner interface when isOwner is true
while (isOwner) {
Console.Clear();
Console.WriteLine ("You are logged in as Owner");
Console.WriteLine ("[q] Quit");
Console.WriteLine ("[c] Create new product");
Console.WriteLine ("[d] Create new animal");
Console.WriteLine ("[i] View all items in the store");
Console.WriteLine ("[t] View all customers");
// string input;
input = Console.ReadLine();
switch (input) {
case "q":
isOwner = false;
break;
case "c":
Console.Clear();
Console.WriteLine ("What type of product do you want to create?");
break;
}
}
} // END of owner interface
Btw:Iveもif文で同じことを試みましたが、同じ結果が得られました。
私はかなり新しいC#を使いました。
入力= Console.ReadLine(); - あなたは入力を入力して、その時点になるとEnterキーを押していますか? –
コードを慎重に実行してください。 'case" c "'になると、コンソールをクリアして、どのプロダクトを作成するかを尋ねます。その後、すぐにwhileループの開始( 'while(isOwner)')に戻り、コンソールをもう一度クリアしてメニューを出力します。あなたのコードは*実行中ですが、あなたはコンソールをすばやくクリアしていますので、表示されません。 – Rob
をデバッグしているときに 'Console.Clear()'を削除することをお勧めします。これは実際に問題の原因を見つけ出しました。 – Kvisgaard