我有一個任務,我需要找到數組中的所有數字的乘積,我不知道如何做到這一點。如何乘數組中的所有值?
int[] numbers = new int[SIZE];
Console.WriteLine("Type in 10 numbers");
Console.WriteLine("To stop, type in 0");
for (int input = 0; input < SIZE; input++)
{
userInput = Console.ReadLine();
numberInputed = int.Parse(userInput);
if (numberInputed == ZERO)
{
numberInputed = ONE;
break;
}
else
{
numbers[input] = numberInputed;
}
}
這就是我試圖找到數組中所有數字的乘積的地方。
foreach (int value in numbers)
{
prod *= value;
}
Console.WriteLine("The product of the values you entered is {0}", prod);
我在foreach語句中做了什麼錯誤?在此先感謝
編輯,離開了我的聲明價值
const int SIZE = 10;
const int ZERO = 0;
string userInput;
int numberInputed;
int prod = 1;
現在,當我在所有十個值類型的作品,但如果我爲了打破循環放了0,那麼一切都等於0怎麼辦我阻止0進入數組?
什麼是與去錯你的代碼? –