Hello all,
I am working through Beginning Microsoft Visual C# 2008 I was asked to create a console application that multiplies 4 input values. I decided to take all 4 values at once and multiply them. Here is my code:
string inputNumbers;
string userName;
Console.WriteLine("Enter your name:");
userName = Console.ReadLine();
Console.WriteLine("Welcome {0}!", userName);
Console.WriteLine("Now give me 4 numbers seperated by a space:");
inputNumbers = Console.ReadLine();
string[] numbers = inputNumbers.Split(' ');
Console.WriteLine("The product of {0} * {1} * {2} * {3} is {4}.",
numbers[0],
numbers[1],
numbers[2],
numbers[3],
Convert.ToDouble(numbers[0]) * Convert.ToDouble(numbers[1]) * Convert.ToDouble(numbers[2]) * Convert.ToDouble(numbers[3])
);
Is there an easier way to do the converts in a loop somehow, or an easier way in general of achieving the same result?