I’m stuck on a problem I’m trying to sort out with calculating multiple arrays.
Here’s the scenario…
A user will input their card number i.e. 1234, and then I need it multiple each number stored in another array in a sequence of 1,2,1,2.
So it would calculate in according 1 * 1, 2 * 2, 3 * 1, 4 * 2, etc.
I’ve tried a few different to calculate both inside a single foreach loop, however I’m having no such luck as I’m returning duplicates, so I’m seeing if there’s even a way I can combine both arrays into a single foreach loop?
I’m able to print the data, so now I’m just seeing how I can multiple them together. Here’s what I have so far…
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your Card Number");
char[] card = Console.ReadLine().ToCharArray();
int[] card_m = { 1,2,1,2 };
foreach (char c in card)
{
int number = (int)char.GetNumericValue(c);
Console.WriteLine("Converted Number: {0}", number);
}
foreach (int m in card_m)
Console.WriteLine("Card Number Multiplier: {0}", m);
Console.Read();
}
}
Assuming the arrays may be different lengths, use the modulus operator to loop on your multiplier array: