Visual Studio はUse of unassigned variable
foriVal
とを言い続けますiNumber
。誰が私が間違っているのか教えてもらえますか?
これは、ユーザーが停止するまで整数の入力と加算を続けるようユーザーに求めるコードになるように設計されています。整数の合計がコンソールに表示されます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AddFive
{
class Program
{
static void Main(string[] args)
{
int iNumber;
int iVal;
int iTotal = 0;
while (iVal > 0)
{
Console.WriteLine("Enter number " + iNumber);
iVal = Convert.ToInt32(Console.ReadLine());
iTotal = iTotal + iVal;
}
if (iNumber <= 0)
{
Console.WriteLine("Total = " + iTotal);
iVal = Convert.ToInt32(Console.ReadLine());
iTotal = iTotal + iVal;
}
Console.WriteLine("Total = " + iTotal);
Console.WriteLine();
Console.WriteLine("Press any key to close");
Console.ReadKey();
}
}
}