C# HELP
Go to solution
Solved by WanderingFool,
You have two choices, well you do have more, but there are two more common choices. Pass the col/row size through parameters, or make them class variables (which I think in this case would make sense).
I chopped it up a bit just to show you how it is done.
Class variable
namespace Pereyra_HW2{ class Pereyra_HW2 { int colSize = 0; //Now this will be accessible for anything in this class int rowSize = 0; static void Main(string[] args) { Console.WriteLine("\t\t\t Magic Square Simulator\n"); do {...rest of code as is
Parameter
static void Main(string[] args) { int colSize = 0; int rowSize = 0; Console.WriteLine("\t\t\t Magic Square Simulator\n"); do { Console.Write("Enter your Magic Square column size(e.g. 5): "); colSize = int.Parse(Console.ReadLine()); if (colSize > 9) Console.WriteLine("SYSTEM OVERLOAD ERROR! Cannot Process more than 9"); else if (colSize < 0) Console.WriteLine("SYSTEM UNDERLOAD ERROR! Cannot Process less than 1"); else if (colSize == 2 || size == 4 || size == 6 || size == 8) Console.WriteLine("SYSTEM ERROR! Odd numbers only"); } while (colSize != 3 && colSize != 5 && colSize != 7 && colSize != 9); GetMagic(colSize, rowSize); //Calling it using parameters } public static int GetMagic(int colSize, int rowSize) { int[,] grid = new int [colSize, rowSize] }
Also for odd numbers
int i = 9;if(i%2 == 0) //Evenif(i%2 == 1) //Odd
Basically % is the remainder if you were to divide.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now