0

How can I make these methods work? (C#)

I'm having problems with my code, specifically with methods. void Grid() { Console.WriteLine(" A B C"); Console.WriteLine("Z[{0}][{1}][{2}]", za, zb, zc); Console.WriteLine("X[{0}][{1}][{2}]", xa, xb, xc); Console.WriteLine("Y[{0}][{1}][{2}]", ya, yb, yc); } void Moves() { string move = Console.ReadLine(); switch (move.ToLower()) { case "za": case "az": za += 1; xa += 2; break; case "xa": case "ax": xa += 1; xb += 2; break; case "ya": case "ay": ya += 1; xa += 2; break; case "zb": case "bz": zb += 1; xb += 2; break; case "xb": case "bx": xb += 1; xc += 2; break; case "yb": case "by": yb += 1; xb += 2; break; case "zc": case "cz": zc += 1; xc += 2; break; case "xc": case "cx": xc += 1; xb += 2; break; case "yc": case "cy": yc += 1; yb += 2; break; default: Console.WriteLine("To make your move, type letter from right and letter from above the grid. E.g ZA"); break; } Grid(); Moves(); // Both of them work just fine without each other, like if I take Moves out, Grid will work and vice versa. If I try to run the code when they are used together, like I have em above, console just starts and closes immediately. What i'm doing wrong?

6th Jun 2018, 11:37 AM
Kuutti
Kuutti - avatar
3 Answers
+ 2
I FIgured it out, I just was careless when writing that code. End bracket for "Moves" method was at wrong place (it wasent visible in that code sample I gave at my frist message, it was much lower).
6th Jun 2018, 2:13 PM
Kuutti
Kuutti - avatar
0
Try ctrl+f5 when you run your program. Or, if that doesn't work, put Console.ReadKey() as the last line of code in your program.
6th Jun 2018, 12:54 PM
Bagshot
Bagshot - avatar
0
Tried both of those, and they didnt work
6th Jun 2018, 2:07 PM
Kuutti
Kuutti - avatar