Jump to content

C# HELP

renz62
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.

Hi guys!

 

So I have this code in C#:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Pereyra_HW2{    class Pereyra_HW2    {        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);        }        public static int GetMagic()        {            int[,] grid = new int [colSize, rowSize]        }    }}

And I want to know how I can get the "colSize" and "rowSize" to link also to the function "GetMagic".

 

And also, any help on the syntax on how to make/compute for an odd numbered magic square would be nice. Thanks! :D

CPU: Intel Core i5-4670k Mobo: MSI Z97 Gaming 3 RAM: Crucial Ballistix Tactical Tracer 8GB 1866 Video Card: MSI GTX 970 GAMING 4G SSDSamsung 840 Evo 250GB HDD: WD 1TB + 500GB Caviar Blue
PSU: EVGA SuperNOVA 750W G2 Case: Gigabyte GZ-G1 Mouse: Corsair M65 RGB Keyboard: Corsair K70 MX Brown MousePad: Corsair MM200
Steam/Origin/Uplay: renz62

Link to comment
Share on other sites

Link to post
Share on other sites

Hi guys!

 

So I have this code in C#:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Pereyra_HW2{    class Pereyra_HW2    {        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);        }        public static int GetMagic()        {            int[,] grid = new int [colSize, rowSize]        }    }}

And I want to know how I can get the "colSize" and "rowSize" to link also to the function "GetMagic".

 

And also, any help on the syntax on how to make/compute for an odd numbered magic square would be nice. Thanks! :D

What exactly do you want to achieve? I dont understand what you wrote.

 

You want the getMagic() function to print out the square of a given size?

Link to comment
Share on other sites

Link to post
Share on other sites

What exactly do you want to achieve? I dont understand what you wrote.

 

You want the getMagic() function to print out the square of a given size?

yes.. that's it!

 

Then i'll just return the results of getMagic() to the main function

CPU: Intel Core i5-4670k Mobo: MSI Z97 Gaming 3 RAM: Crucial Ballistix Tactical Tracer 8GB 1866 Video Card: MSI GTX 970 GAMING 4G SSDSamsung 840 Evo 250GB HDD: WD 1TB + 500GB Caviar Blue
PSU: EVGA SuperNOVA 750W G2 Case: Gigabyte GZ-G1 Mouse: Corsair M65 RGB Keyboard: Corsair K70 MX Brown MousePad: Corsair MM200
Steam/Origin/Uplay: renz62

Link to comment
Share on other sites

Link to post
Share on other sites

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.

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

-snip-

Thank you very much for the help!! :D

CPU: Intel Core i5-4670k Mobo: MSI Z97 Gaming 3 RAM: Crucial Ballistix Tactical Tracer 8GB 1866 Video Card: MSI GTX 970 GAMING 4G SSDSamsung 840 Evo 250GB HDD: WD 1TB + 500GB Caviar Blue
PSU: EVGA SuperNOVA 750W G2 Case: Gigabyte GZ-G1 Mouse: Corsair M65 RGB Keyboard: Corsair K70 MX Brown MousePad: Corsair MM200
Steam/Origin/Uplay: renz62

Link to comment
Share on other sites

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×