Here's the code as is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace String_Reduction_Test
{
public class Variables
{
public static char confirmation = 'n';
}
public class Functions
{
public static void string_to_char()
{
string input_text;
char[] output_character = new char[256];
input_text = Console.ReadLine();
for (int i = 0; i < input_text.Length; i++)
{
output_character[i] = input_text[i];
}
Variables.confirmation = output_character[0];
input_text = null;
output_character = null;
}
public static void opening_menu()
{
Console.WriteLine("PlaneGates#");
Console.WriteLine("\n");
while (Variables.confirmation != 'y' || Variables.confirmation != 'Y')
{
Console.WriteLine("Start New Game? Y/N");
Functions.string_to_char();
if (Variables.confirmation != 'Y' && Variables.confirmation != 'N' && Variables.confirmation != 'y' && Variables.confirmation != 'n')
{
Console.WriteLine("Error");
}
if (Variables.confirmation == 'n' || Variables.confirmation == 'N')
{
Console.WriteLine("\"Negative Message\"");
}
if (Variables.confirmation != 'y' && Variables.confirmation != 'Y')
{
Variables.confirmation = 'n';
}
Console.Read();
}
}
}
class Program
{
static void Main(string[] args)
{
Functions.opening_menu();
}
}
}
Now, basically what should happen is the console should ask the user if he wants to start a new game and:
If he types any letter other than y or Y, it loops and asks again.
If he types y or Y, it leaves the loop.
What IS happening, as any quick compilation will show you, is the code is looping regardless of what is pressed and it is skipping the entire Functions.string_to_char method and assuming an Error message, i.e. it is entering the "if" loop for Variables.confirmation different from n, N, y or Y. Any reasons why this happens? I'm imagining it is regarding Variables.confirmation as null after the first round of the "while" loop, but I don't understand why.
And please bear in mind I am a newbie. Don't crush my hopes and dreams... Too harshly. And any "good practice" hints that I may not have known about are welcome.
I'm using Visual Studio 2010 Ultimate, if that makes much of a difference.


Sign In
Create Account

Back to top









