hallkids1 hallkids1 - 3 months ago 14
C# Question

What is the best way to multiply this code all together instead of individually multiplying each one?

I'm trying to make a math program that can multiply three variables at once, and i don't know the best way to do that

Console.WriteLine("Input your x");
var g = Console.ReadLine();
int x = Convert.ToInt32(g);

Console.WriteLine("Input your y");
var f = Console.ReadLine();
int y = Convert.ToInt32(f);

Console.WriteLine("Input your z");
var l = Console.ReadLine();
int z = Convert.ToInt32(l);


If you want to do the Math function inline then you can do this

Console.WriteLine($"{x}\t{y}\t{z} = {x * y * z}");

And if you would prefer to have a variable stored

int m = x * y * z;
Console.WriteLine($"{x}\t{y}\t{z} = {m}");