【C#】ランダムで入力した数値の計算の出力ができない
Q&A
【C#】ランダムで入力した数値の計算の出力ができない
現在ランダムで入力した数値を式に代入して計算結果を出力するプログラムを作っているのですが、以下のようなエラーが出てしまっています。ご存じの方がいらっしゃいましたらご教授頂けると幸いです。
発生している問題・エラー
Unhandled Exception:
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x00020] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x0001c] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Int32.Parse (System.String s) [0x00019] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at Program.Main () [0x00006] in /workspace/Main.cs:7
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x00020] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x0001c] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Int32.Parse (System.String s) [0x00019] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at Program.Main () [0x00006] in /workspace/Main.cs:7
以下がソースコードで、HとLにランダムな整数の数値を代入します。
該当するソースコード
using System;
class Program
{
static void Main()
{
var H =int.Parse(Console.ReadLine());
var L =int.Parse(Console.ReadLine());
Console.WriteLine(H-L);
}
}
0 likes