I need some help.
I have a problem and I am having some trouble.
Problem: Write a console application that calculates the product of a string of numbers. The numbers are added 1 by 1 on each line and the app will read them 1 after each other ulti the user's input X. After the x the app will stop and show the product of all numbers.
EX: input -
This is my code
` string inputData = Console.ReadLine();
int numbers = Convert.ToInt32(inputData);
int numbersArr = new int[numbers];
var product = 0;
for (int i = 0; i < numbersArr.Length; i++)
numbersArr[i] = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < numbersArr.Length; i++ )
if (inputData == "x")
Console.WriteLine(product *= numbersArr[i]);
The problems I have.
I can't make it so the user can add as many numbers as he wants. I tried. i < numbersArray.Length but this way the user needs to add first the amount of the numbers that they will add. I tried i < 100 but if the first number was 7 it would let me add 8 numbers without 7 and if it was 5 I could add 6 without the 5. And after that would break. And I tried a few more stuff also.
The other problem is that I don't know if what I am trying to calculate is correct. I was looking on google on how to get the product of all the numbers from an Array and that's what I found.
Can you help me?