C#
1using System; 2 3namespace RPG経験値計算 4{ 5 class Program 6 { 7 string input; 8 int Lv; 9 int OneUpExp; 10 int AllExp; 11 bool End; 12 bool IntegerIsEntered; 13 14 static void Main() 15 { 16 Program p = new Program(); 17 Console.WriteLine("終了したい場合はendを、経験値の計算をしたい場合は整数を入力してください"); 18 while (!p.End) 19 { 20 p.Input(); 21 if (p.IntegerIsEntered) 22 { 23 p.Calculation(); 24 p.Output(); 25 } 26 } 27 } 28 29 void Input() 30 { 31 input = Console.ReadLine(); 32 if (input.Contains("end")) End = true; 33 else if (int.TryParse(input, out Lv)) IntegerIsEntered = true; 34 else 35 { 36 Console.WriteLine("endまたは整数を入力してください"); 37 IntegerIsEntered = false; 38 } 39 } 40 41 void Calculation() 42 { 43 AllExp = Lv * Lv * 1000; 44 OneUpExp = Lv * Lv * 1000; 45 Lv--; 46 OneUpExp -= Lv * Lv * 1000; 47 } 48 49 void Output() 50 { 51 Console.Write("レベルを1つ上げるために必要な経験値:"); 52 Console.WriteLine(OneUpExp); 53 54 Console.Write("このレベルに達するために必要な経験値"); 55 Console.WriteLine(AllExp); 56 Console.ReadKey(); 57 } 58 } 59}
これを実行してから整数を1度入力すると、次にendもしくは整数を入力した時の反応がおかしい
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/05 11:51