C
C#2y ago
Mekasu0124

❔ ✅ Pass A Function To Another Function?

// in ErrorHandlers.cs
public void InputInvalid(string error) // pass function with unknown parameter types and unknown number of parameters
{
if (tries > 0)
{
Console.WriteLine("\n" + error + " " + tries + " Tries Left");
// recall passed function here
}
else
{
Console.WriteLine("\nNumber Of Attempts Reached. Returning To Welcome Screen.");
Thread.Sleep(2000);
Console.Clear();
Program program = new();
program.WelcomeScreen();
}
}
// in ErrorHandlers.cs
public void InputInvalid(string error) // pass function with unknown parameter types and unknown number of parameters
{
if (tries > 0)
{
Console.WriteLine("\n" + error + " " + tries + " Tries Left");
// recall passed function here
}
else
{
Console.WriteLine("\nNumber Of Attempts Reached. Returning To Welcome Screen.");
Thread.Sleep(2000);
Console.Clear();
Program program = new();
program.WelcomeScreen();
}
}
Let's say I have 4 functions. The first function is an error handler that needs to have the parameters of a string and a function. The other 3 functions are functions that execute code and have unknown parameters and parameter types. How would I pass those 3 functions to the error handling function so that the error handling function can call them over again when needed?
415 Replies
JakenVeina
JakenVeina2y ago
what does that even mean? unknown parameters and unknown parameter types? why does the error handling function meed such a thing? what is the error handling function supposed to DO with that?
Mekasu0124
Mekasu0124OP2y ago
not trying to come off rude or anything, but when ya'll ask questions like that, I feel like I have to defend my code and why I'm doing something instead of just getting helping doing what I'm trying to do. If you go back to this thread https://discordapp.com/channels/143867839282020352/1112175696547168377 you'll see where I took a giant if/else statement and broke it down into separate functions. I'm now taking those separated functions and instead of having to write the same functions in each file, I'm putting them into one file named ErrorHandlers.cs so that I can just call the necessary error handling function when needed. This function that I've shown above needs to be able to call the passed function again while tries is greater than zero. An example is here https://pastebin.com/teHhQSkR <- in this file, I have 3 helper functions: InputInvalid, CheckInputIsInteger, CheckCorrectIndex. The 2 later functions use the the InputInvalid function which calls ScreenSelection over while tries is greater than 3 to allow the user to see the menu and input their selection again. I've moved these 3 functions to a separate file to prevent from having to write them at the top of every single file I create within my project. Write once, re-use 100 times. The only problem with having my InputInvalid function in a separate file is that it doesn't know which function to call while tries is greater than 0, so I need to be able to pass a function to it.
unknown parameters and unknown parameter types?
In response to this, it is what it states. Passing function a to function b without function b knowing what parameters function a has. This allows it to be used for any function I pass to it and the function gets executed properly. I just don't know how to do that in C#. In python, it would just be function_a(*args, **kwargs) but C# is nothing like python so I'm asking for help on how to pass a function with unknown parameters and parameter types to another function so that the function can be called again like function A could have a string parameter. function B could have 2 string and 1 list parameter, and function C could have 3 intergers and a string parameter but the error handling function doesn't know that but it still needs to be able to call the function that is passed to it whether it's function a, b, or c
JakenVeina
JakenVeina2y ago
I'm not asking you to justify your code I'm asking you to clarify what you mean because that affects the answer what is the error handling function supposed to do with the function you pass it? is it supposed to call it?
Mekasu0124
Mekasu0124OP2y ago
this is answered in my original message
JakenVeina
JakenVeina2y ago
how does it do that without being able to pass parameters? is it not supposed to call it? then what IS it supposed to do? the mechanism you need depends on your requirements
snowy | switching accounts
long time since i've seem you talk in the general chat how are you my guy
JakenVeina
JakenVeina2y ago
same as ever, I suppose
snowy | switching accounts
@Mekasu Can you explain your intent and what is your purpose?
Mekasu0124
Mekasu0124OP2y ago
I'm not doing that. I just wrote a f'n book explaining what I'm trying to do
snowy | switching accounts
Receiving "functions" without knowing what they are or what they do is a bit weird, you usually don't want to do that
JakenVeina
JakenVeina2y ago
and yes, if I think your approach here doesn't make sense, I will absolutely suggest better alternatives. After answering the initial question as much as possible. right, now take that book and trim it down to something useful
Mekasu0124
Mekasu0124OP2y ago
or just read the thing.
snowy | switching accounts
calm down mate
Mekasu0124
Mekasu0124OP2y ago
i edited my message. i cuss as general term usage. I'm not upset but it's as simple as it sounds. the helper function is going to be passed various functions with various parameters, so the helper function needs to be able to accept any function and call it again it makes it so that the error handling function can be used universally without strict parameter types
JakenVeina
JakenVeina2y ago
what is the error handler doing with the function you pass it? Presumably it's going to call it? How? Where do the arguments come from?
snowy | switching accounts
You just can't do things dynamically as you want to do, unless you have some sort of "ioc container" that would automatically solve dependencies for you. That's just how C# works. When calling the delegate you'd need to pass down parameters specifying what they are in order for the function to work out. You will have to type at some point.
JakenVeina
JakenVeina2y ago
not necessarily true
snowy | switching accounts
Enlighten me on how would a person do that without a dictionary and a lot of spare time when
JakenVeina
JakenVeina2y ago
probably wouldn't RECOMMEND doing whatever dynamic or relfection solution is gonna be necessary for this, but it's most likely possible
Mekasu0124
Mekasu0124OP2y ago
ok lets try this one moment
snowy | switching accounts
@Mekasu Can you just summarize for us what is your final goal? In a shorter message you love
Mekasu0124
Mekasu0124OP2y ago
I've tried doing that and no one but me seems to understand what I'm saying so without being able to just share my screen and verbally explain, I'm going to use code. just a second
class MainMenu
{
public ErrorHandlers errorHandle = new();
public void ScreenSelection()
{
List<string> initialText = new()
{
"What Would You Like To Do?",
"--------------------------",
"** Submit Answer As 1, 2, or 3 **"
};

List<string> initialSelection = new()
{
"1) Play Game",
"2) View Previous Games",
"3) View Statistics"
};

foreach (string text in initialText)
{
Console.WriteLine(text);
};

foreach (string text in initialSelection)
{
Console.WriteLine(text);
};

bool isInteger = errorHandle.CheckInputIsInteger(Console.ReadLine(), out int userSelection);
bool isCurrentIndex = errorHandle.CheckCorrectIndex(
userSelection,
initialSelection,
initialSelection.Count,
out string selectedAction);

LaunchGameScreen(selectedAction);
}

public void LaunchGameScreen(string selectedAction)
{
switch (selectedAction)
{
case "play game":
break;

case "view previous games":
break;

case "view statistics":
break;

default:
errorHandle.InputInvalid("Error Launching Game Screen. Trying Again. Please Wait. . .");
break;
}
}
}
class MainMenu
{
public ErrorHandlers errorHandle = new();
public void ScreenSelection()
{
List<string> initialText = new()
{
"What Would You Like To Do?",
"--------------------------",
"** Submit Answer As 1, 2, or 3 **"
};

List<string> initialSelection = new()
{
"1) Play Game",
"2) View Previous Games",
"3) View Statistics"
};

foreach (string text in initialText)
{
Console.WriteLine(text);
};

foreach (string text in initialSelection)
{
Console.WriteLine(text);
};

bool isInteger = errorHandle.CheckInputIsInteger(Console.ReadLine(), out int userSelection);
bool isCurrentIndex = errorHandle.CheckCorrectIndex(
userSelection,
initialSelection,
initialSelection.Count,
out string selectedAction);

LaunchGameScreen(selectedAction);
}

public void LaunchGameScreen(string selectedAction)
{
switch (selectedAction)
{
case "play game":
break;

case "view previous games":
break;

case "view statistics":
break;

default:
errorHandle.InputInvalid("Error Launching Game Screen. Trying Again. Please Wait. . .");
break;
}
}
}
JakenVeina
JakenVeina2y ago
sounds good
Mekasu0124
Mekasu0124OP2y ago
this is my MainMenu the functions ScreenSelection and LaunchGameScreen use helper functions
using MeksMathGameV3;

class ErrorHandlers
{
public int tries = 3;

public bool ReadyCheckInput(string userInput)
{
if (userInput.ToLower() == "yes")
{
return true;
}
else
{
return false;
}
}

public bool CheckInputIsInteger(string userInput, out int value)
{
if (int.TryParse(userInput, out value))
{
return true;
}
else
{
tries--;
InputInvalid("Input Is Not An Integer. Try Again!");
}
return false;
}

public bool CheckCorrectIndex(int userInput, List<string> listObject, int maxValue, out string value)
{
if (userInput >= 1 && userInput <= maxValue)
{
value = listObject[userInput - 1];
return true;
}
else
{
tries--;
InputInvalid("Input Is Out Of Range For Given List. " +
"Input A Value Between 0 and " + maxValue);
}
value = null;
return false;
}

public void InputInvalid(string error)
{
if (tries > 0)
{
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
// recall function
}
else
{
Console.WriteLine("\nNunber Of Attempts Reached. Returning To Welcome Screen.");
Thread.Sleep(2000);
Console.Clear();

Program program = new();
program.WelcomeScreen();
}
}
}
using MeksMathGameV3;

class ErrorHandlers
{
public int tries = 3;

public bool ReadyCheckInput(string userInput)
{
if (userInput.ToLower() == "yes")
{
return true;
}
else
{
return false;
}
}

public bool CheckInputIsInteger(string userInput, out int value)
{
if (int.TryParse(userInput, out value))
{
return true;
}
else
{
tries--;
InputInvalid("Input Is Not An Integer. Try Again!");
}
return false;
}

public bool CheckCorrectIndex(int userInput, List<string> listObject, int maxValue, out string value)
{
if (userInput >= 1 && userInput <= maxValue)
{
value = listObject[userInput - 1];
return true;
}
else
{
tries--;
InputInvalid("Input Is Out Of Range For Given List. " +
"Input A Value Between 0 and " + maxValue);
}
value = null;
return false;
}

public void InputInvalid(string error)
{
if (tries > 0)
{
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
// recall function
}
else
{
Console.WriteLine("\nNunber Of Attempts Reached. Returning To Welcome Screen.");
Thread.Sleep(2000);
Console.Clear();

Program program = new();
program.WelcomeScreen();
}
}
}
these are my helper functions ScreenSelection passes information off to CheckInputIsInteger and CheckCorrectIndex which therein both use InputInvalid The LaunchGameScreen function in MainMenu also uses InputInvalid When the user inputs anything other than an integer, input invalid is called. When the input is invalid, it calls ScreenSelection over again to show the user the menu options and to allow them to try again same with checking the index. it calls ScreenSelector over again when the number input doesn't match the list
JakenVeina
JakenVeina2y ago
yup
Mekasu0124
Mekasu0124OP2y ago
the LaunchGameScreen function also uses the InputInvalid function but in a slightly different manor. When it can't launch the desired screen, it tries 2 more times after that, but whilst trying it calls itself over again by passing a function to the helper function InputInvalid, the function needs to know whether it needs to call ScreenSelection or LaunchGameScreen over again however, ScreenSelection has no parameters where LaunchGameScreen has a string parameter
JakenVeina
JakenVeina2y ago
right
Mekasu0124
Mekasu0124OP2y ago
what do I mean by not knowing the parameters and types? simple More than just these 2 functions through my program is going to all use this InputInvalid helper function
JakenVeina
JakenVeina2y ago
but if you DO decide to call LaunchGameScreen.. how do you pass it a parameter more specifically, what parameter do you pass to it?
Mekasu0124
Mekasu0124OP2y ago
those various functions are going to have various types of parameters, but I can't write the helper functions parameters to fit all those different functions as those functions needs their parameters to be called again
snowy | switching accounts
Is there any specific reason on why you're doing things like that instead of simply using a loop or controlling the flow of the app in a better way? I understand what you want but I just don't understand why
Mekasu0124
Mekasu0124OP2y ago
in my original code, https://pastebin.com/WXJhPwBE, the functions were written for the file itself so I could just hardcode the parameters and function calls right there in them, but the helper functions are no longer being written in the files themselves as I found I was writing the same helper functions over and over again why write them over and over again when I can just put them in one file and use them universally
JakenVeina
JakenVeina2y ago
we can DEAL with the problem of not knowing what the types and parameters are at compile time but you still have to HAVE them they have to come from SOMEWHERE if you want to call the function
Florian Voß
Florian Voß2y ago
so essentially you are trying to write an IsInputValid function that checks any and every input in your whole app because you are afraid that writing another method that validates certain input might be code repetition but it really isn't. Validating different inputs are different concerns and responsibilities. Seperate it and do oop
JakenVeina
JakenVeina2y ago
I'm not even sure if that's the case
Florian Voß
Florian Voß2y ago
thats what I understand from wanting to take any params and calling any function based of that
Mekasu0124
Mekasu0124OP2y ago
I'll just put the input invalid function back in the files. I don't know anymore
JakenVeina
JakenVeina2y ago
yeah, let's stop overwhelming him the question stands
Mekasu0124
Mekasu0124OP2y ago
just stop
JakenVeina
JakenVeina2y ago
where are the parameters coming from
Mekasu0124
Mekasu0124OP2y ago
without being able to get in voice and share my screena nd explain, I don't know anymore I've tried to explain this the best way that I can and it's failing I've tried showing code to help explain and thats failing to so I just don't know anymore. maybe c# isn't a lagnuage for me
JakenVeina
JakenVeina2y ago
you've shown the code for the methods you want to wrap up and pass around dynamically that's great I haven't seen anything about the code where you intend to call whatever method was passed
Mekasu0124
Mekasu0124OP2y ago
public void LaunchGameScreen(string selectedAction)
{
switch (selectedAction)
{
case "play game":
break;

case "view previous games":
break;

case "view statistics":
break;

default:
errorHandle.InputInvalid("Error Launching Game Screen. Trying Again. Please Wait. . .");
break;
}
}
public void LaunchGameScreen(string selectedAction)
{
switch (selectedAction)
{
case "play game":
break;

case "view previous games":
break;

case "view statistics":
break;

default:
errorHandle.InputInvalid("Error Launching Game Screen. Trying Again. Please Wait. . .");
break;
}
}
when this function calls InputInvalid, InputInvalid needs to be able to call this function again
JakenVeina
JakenVeina2y ago
with the same parameters so there's the key
Mekasu0124
Mekasu0124OP2y ago
public bool CheckInputIsInteger(string userInput, out int value)
{
if (int.TryParse(userInput, out value))
{
return true;
}
else
{
tries--;
InputInvalid("Input Is Not An Integer. Try Again!");
}
return false;
}

public bool CheckCorrectIndex(int userInput, List<string> listObject, int maxValue, out string value)
{
if (userInput >= 1 && userInput <= maxValue)
{
value = listObject[userInput - 1];
return true;
}
else
{
tries--;
InputInvalid("Input Is Out Of Range For Given List. " +
"Input A Value Between 0 and " + maxValue);
}
value = null;
return false;
}
public bool CheckInputIsInteger(string userInput, out int value)
{
if (int.TryParse(userInput, out value))
{
return true;
}
else
{
tries--;
InputInvalid("Input Is Not An Integer. Try Again!");
}
return false;
}

public bool CheckCorrectIndex(int userInput, List<string> listObject, int maxValue, out string value)
{
if (userInput >= 1 && userInput <= maxValue)
{
value = listObject[userInput - 1];
return true;
}
else
{
tries--;
InputInvalid("Input Is Out Of Range For Given List. " +
"Input A Value Between 0 and " + maxValue);
}
value = null;
return false;
}
when these functions call InputInvalid, InputInvalid needs to be able to call the function over again from where the function called them to start with
JakenVeina
JakenVeina2y ago
InputInvalid does not need to call a function with any number or types of parameters cause it doesn't have those parameters it needs to call a function with NO parameters and it's your job to give it one InputInvalid needs an Action and the caller needs to do... whatever it wants you can use an anonymous closure for that
InputInvalid("Whatevs", () => CheckCorrectIndex(userInput, listObject, maxValue, value));
InputInvalid("Whatevs", () => CheckCorrectIndex(userInput, listObject, maxValue, value));
Mekasu0124
Mekasu0124OP2y ago
This file contains 2 main methods. The first being SelectionScreen which prompts for user inputs and validates them. The validators at the top call correctly with decrementing tries for the user to attempt to get the input correct, or it defaults back to the previous screen. The second main method is at the bottom, LaunchGameScreen(string selectedAction). This function attempts to launch the desired screen and decrements tries if it can't until tries runs out and it defaults back to the previous screen. The problem with this file is that when LaunchGameScreen fails on attempt one, it recalls ScreenSelection instead of LaunchGameScreen again to give it another try. That's what I'm trying to fix. If it's not fixable to where both ScreenSelection and LaunchGameScreen can both use the InputInvalid function, then I'll put the countdown logic back into the LaunchGameScreens default case. I don't know anything about an action as the "basics tutorial" that I learned from didn't teach that so at this point, I'm lost and have no clue and just really do feel like giving up. This is just supposed to be a simple math game that The C# Academy has beginners doing. I have re-written this flipping game countless times over the last week and I can't figure this crap out and it's becoming too much.
Mekasu0124
Mekasu0124OP2y ago
it doesn't matter. I need a break. Thanks for what you guys have done. I'm going to bed. good night I'm going back to the very basics and trying again. This time, it's a simple while loop
public int tries = 3;
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

while (userReady != "yes" || userReady != "no")
{
tries--;
Console.WriteLine("Invalid Input. Enter yes To Begin Or no To exit");
}
}
public int tries = 3;
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

while (userReady != "yes" || userReady != "no")
{
tries--;
Console.WriteLine("Invalid Input. Enter yes To Begin Or no To exit");
}
}
This loop continues for 3 tries giving the user 3 chances to get the right input. In python, I would write
while userReady != "yes" or userReady != "no":
# show error
# allow another input
else:
if userReady == "yes":
# launch wanted screen
else:
# close program
while userReady != "yes" or userReady != "no":
# show error
# allow another input
else:
if userReady == "yes":
# launch wanted screen
else:
# close program
so how do I do this basic while loop in c#? I'm not going to give up just because it got tough
JakenVeina
JakenVeina2y ago
something like...
Mekasu0124
Mekasu0124OP2y ago
and @ReactiveVeina @Florian Voß and @snowy I'm sorry for my attitude earlier. I'm trying to get better at not getting so upset when I can't figure this stuff out. It's no ones fault but my own and I'm sorry
JakenVeina
JakenVeina2y ago
for(var failureCount = 0; failureCount < 3; ++failureCount)
{
// Retireve User Input
if (/*User Input is Valid*/)
break;
}
if (userSelection is null)
// End Program
for(var failureCount = 0; failureCount < 3; ++failureCount)
{
// Retireve User Input
if (/*User Input is Valid*/)
break;
}
if (userSelection is null)
// End Program
Mekasu0124
Mekasu0124OP2y ago
so I wouldn't use a while loop at all?
JakenVeina
JakenVeina2y ago
maybe
Mekasu0124
Mekasu0124OP2y ago
would it be more efficient to use a for loop?
JakenVeina
JakenVeina2y ago
if you want to put that upper limit in, a for ends up being simpler for tracking that
Mekasu0124
Mekasu0124OP2y ago
ok not a bad idea
JakenVeina
JakenVeina2y ago
the tricky part about using a while directly on the input is that the while evaluates at the beginning of the loop so either you duplicate the code to retrieve user input, both before the loop and within it, or you put it only inside the loop with a custom break, and a condition that ensures the loop runs at least once without the retry limit, it coupd maybe also be a do while
do
{
// Get User Input
} while(/*User Input is not valid*/);
do
{
// Get User Input
} while(/*User Input is not valid*/);
there's a bunch of ways you could organize it, semantically, most are equally valid
Mekasu0124
Mekasu0124OP2y ago
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
break;
}
}

if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
}
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
break;
}
}

if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
}
I went with this. thoughts? I don't think that's right. From my point of view, this is giving the user 3 tries to input yes or no and when the loop ends, it's checking for yes but there is no check for no and there is no handle for what to do if they run out of chances
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

Environment.Exit(0);
break;
}
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");

string userReady = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

Environment.Exit(0);
break;
}
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
what about this? so i moved getting the user input inside the loop, but its not recognizing when i insert no or yes for that matter
JakenVeina
JakenVeina2y ago
you aren't actually repeating the user input retreival, on retry
Mekasu0124
Mekasu0124OP2y ago
and I honestly feel like this is too much code for what I'm trying to do
JakenVeina
JakenVeina2y ago
it's not
Mekasu0124
Mekasu0124OP2y ago
so how can I fix it in less code?
JakenVeina
JakenVeina2y ago
UI is hard
Mekasu0124
Mekasu0124OP2y ago
oh.
JakenVeina
JakenVeina2y ago
even text UI
Mekasu0124
Mekasu0124OP2y ago
so where do I need to put the user input capture for it to work correctly?
JakenVeina
JakenVeina2y ago
somewhere inside the loop, for starters otherwise, it won't repeat
Mekasu0124
Mekasu0124OP2y ago
I did that
JakenVeina
JakenVeina2y ago
oh, missed that line
Mekasu0124
Mekasu0124OP2y ago
current code
JakenVeina
JakenVeina2y ago
your retry condition is wrong
Mekasu0124
Mekasu0124OP2y ago
I'm not understanding how I'm sorry
JakenVeina
JakenVeina2y ago
think it through
Mekasu0124
Mekasu0124OP2y ago
it's supposed to be if not yes or if not no
JakenVeina
JakenVeina2y ago
what happens when the input value is "yes"
Mekasu0124
Mekasu0124OP2y ago
it iterates again saying that it's wrong
JakenVeina
JakenVeina2y ago
why?
Mekasu0124
Mekasu0124OP2y ago
idk. fail safe against accidental key presses?
JakenVeina
JakenVeina2y ago
how does the condition evaluate?
Mekasu0124
Mekasu0124OP2y ago
right now, it doesn't matter if I enter yes or no, it fails
Welcome To Mek's Math Game!
Some Rules Of Thumb To Remember While Playing:
1) All Answers Are In The Form Of An Integer.
2) If Your Division Answer Gives You A Decimal Like: 0.86, Then Your Answer Is 0
3) This Game Has 3 Difficulties: Easy, Medium, and Hard.
4) None Of The Numbers You Will Encounter On Any Difficulty Will Go Higher Than 100.

When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.

yes
Enter Either yes To Start Or no To Exit.
no
Enter Either yes To Start Or no To Exit.
Welcome To Mek's Math Game!
Some Rules Of Thumb To Remember While Playing:
1) All Answers Are In The Form Of An Integer.
2) If Your Division Answer Gives You A Decimal Like: 0.86, Then Your Answer Is 0
3) This Game Has 3 Difficulties: Easy, Medium, and Hard.
4) None Of The Numbers You Will Encounter On Any Difficulty Will Go Higher Than 100.

When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.

yes
Enter Either yes To Start Or no To Exit.
no
Enter Either yes To Start Or no To Exit.
JakenVeina
JakenVeina2y ago
right think through the condition that you wrote how does it evaluate when the input is "yes"
Mekasu0124
Mekasu0124OP2y ago
if the user inputs yes or inputs no, it is supposed to trigger the else part of the if statement and then check if yes, then launch. If no, then exit
JakenVeina
JakenVeina2y ago
right, we know what it's supposed to do I'm asking you to think about what it IS doing
Mekasu0124
Mekasu0124OP2y ago
^
JakenVeina
JakenVeina2y ago
^
Mekasu0124
Mekasu0124OP2y ago
same thing. It doesn't matter what I put in. RIght now it's just failing in general
JakenVeina
JakenVeina2y ago
the condition how does the condition evaluate
Mekasu0124
Mekasu0124OP2y ago
apparently I'm just to stupid to get it because my answer isn't going to change. The condition is failing regardless as to what is entered.
JakenVeina
JakenVeina2y ago
yes and you need to think it through to figure out why youbhaven't told me anything about how the condition evaluates
(userReady != "yes") || (userReady != "no")
(userReady != "yes") || (userReady != "no")
evaluate this for me with a value of "yes" for userReady
Mekasu0124
Mekasu0124OP2y ago
that's an invalid expression due to the inner parenthesis
JakenVeina
JakenVeina2y ago
....no?
Mekasu0124
Mekasu0124OP2y ago
yes
Mekasu0124
Mekasu0124OP2y ago
wait I'm dumb nevermind
JakenVeina
JakenVeina2y ago
that is invalid syntax for an if statement, yes
Mekasu0124
Mekasu0124OP2y ago
yea I'm dumb. forgot a parenthesis
JakenVeina
JakenVeina2y ago
in any case, I didn't ask you to write it in code particularly as that is the code you already had I asked you to evaluate it for me
Mekasu0124
Mekasu0124OP2y ago
ok at this point I'm just ignorant. I apparently can't
JakenVeina
JakenVeina2y ago
you don't know how boolean operators work?
Mekasu0124
Mekasu0124OP2y ago
|| I was told this was an or symbol
JakenVeina
JakenVeina2y ago
indeed which means what?
Mekasu0124
Mekasu0124OP2y ago
one or the other
JakenVeina
JakenVeina2y ago
to be colloquial, yes and !=?
Mekasu0124
Mekasu0124OP2y ago
if (userReady != "yes" || userReady != "no") if userReady does not equal yes, or userReady does not equal no
JakenVeina
JakenVeina2y ago
that is an accurate colloquial restatement of the condition, yes what does that evaluate to when userInput is "yes"?
Mekasu0124
Mekasu0124OP2y ago
ok at this point I must be a great laugh or something because I seriously feel like I'm just going in circles. I've stated several times that it keeps failing. If I'm missing something then at this point just please tell me otherwise I'm going to trash the whole thing because this is becoming really redundant for me and I'm tired of feeling stupid I'm not blaming you for my ignorance. I'm just expressing my current feelings
JakenVeina
JakenVeina2y ago
good regarding expressing your feelings I am asking you to evaluate something and you continue to tell me about your intentions for this code, and what you are experiencing with this code you have yet to evaluate the experession I am asking you to evaluate your question at this point should probably be "what do you mean by evaluate"
Mekasu0124
Mekasu0124OP2y ago
ok sure
JakenVeina
JakenVeina2y ago
what is the value of userReady that we're evaluating for?
Mekasu0124
Mekasu0124OP2y ago
yes or no
JakenVeina
JakenVeina2y ago
which one?
Mekasu0124
Mekasu0124OP2y ago
I'm checking to see if it's either of those
JakenVeina
JakenVeina2y ago
yes, that is the behavior you're trying to wrote code for the code is not working the behavior you are experiencing is that when the user enters "yes" your code does not behave as intended so we are going to evaluate your code for a userReady value of "yes" which is what I kept asking you to do so, what is the value of userReady that we are evaluating for? "yes" the condition we're evaluating is
(userReady != "yes") || (userReady != "no")
(userReady != "yes") || (userReady != "no")
is "yes" equal to "yes"?
Mekasu0124
Mekasu0124OP2y ago
this shit literally has me crying like I feel so dumb if the user enters "yes" then it's supposed to pass this check and go to the else statement
JakenVeina
JakenVeina2y ago
again you are describing the behavior you want we already know that the code is not giving you the behavior you want we are trying to debug the code which involves thinking about what the code is ACTUALLY doing, as opposed to what you WANTED it to do stop derailing and answer the questions presented is "yes" equal to "yes"?
Mekasu0124
Mekasu0124OP2y ago
yes
JakenVeina
JakenVeina2y ago
so, what does userReady != "yes" evaluate to?
Mekasu0124
Mekasu0124OP2y ago
false if not yes
JakenVeina
JakenVeina2y ago
incorrect
Mekasu0124
Mekasu0124OP2y ago
i giv eup
JakenVeina
JakenVeina2y ago
whst is userReady?
Mekasu0124
Mekasu0124OP2y ago
a string and a variable
JakenVeina
JakenVeina2y ago
the value that we're evaluating for
Mekasu0124
Mekasu0124OP2y ago
a string
JakenVeina
JakenVeina2y ago
the value
Mekasu0124
Mekasu0124OP2y ago
users input. jesus christs left toe my dude I don't know
JakenVeina
JakenVeina2y ago
yes you do the value of userReady that we are evaluating for is "yes" because that is the value you put into your program that resulted in behavior you didn't want is "yes" equal to "yes"?
Mekasu0124
Mekasu0124OP2y ago
and we're back to beginning of that circle
JakenVeina
JakenVeina2y ago
we are "yes" is in fact equal to "yes" so (userReady != "yes") evaluates to false what does (userReady != "no") evaluate to?
Mekasu0124
Mekasu0124OP2y ago
all of my answers are continuously wrong so I'm just letting you explain. I'm not going to feel stupid anymore
JakenVeina
JakenVeina2y ago
your answers are much more "not answers" than wrong
Mekasu0124
Mekasu0124OP2y ago
if my statement is backwards, then just tell me that. If I need to put my true check at the top instead of the bottom then tell me that. Otherwise, this mulberry bush isn't going anywhere as I'm obviously not getting the point
JakenVeina
JakenVeina2y ago
you don't know what (userReady != "no") evaluates to when userReady is "yes"?
Mekasu0124
Mekasu0124OP2y ago
i guess it would be false shrugs i don't know
JakenVeina
JakenVeina2y ago
is "yes" equal to "no"?
Mekasu0124
Mekasu0124OP2y ago
i guess not
JakenVeina
JakenVeina2y ago
then what does != return?
Mekasu0124
Mekasu0124OP2y ago
i guess false
JakenVeina
JakenVeina2y ago
!= oh, hush, @MODiX what does != return when the values being compared are not equal?
Mekasu0124
Mekasu0124OP2y ago
i guess false
JakenVeina
JakenVeina2y ago
don't guess know
Mekasu0124
Mekasu0124OP2y ago
i don't know anything. I've been trying to get you to understand that and you won't. So therefore, I guess
JakenVeina
JakenVeina2y ago
if you legitimately don't know, go read the docs page horseshit you know everything you need to solve this problem or you would never have gotten this far not to mention you proved you know EXACTLY how the != operator works when you answered effortlessly earlier you are stressed and need to take a break or you are just being lazy and hoping I'll give up and give you the answer
Mekasu0124
Mekasu0124OP2y ago
it is neither. It's as simple as I'm obviously not getting it and unless some miracle happens, I'm not going to. It's literally as simple as
user_ready = "yes"

if user_ready != "yes" or user_ready != "no":
print("wrong input")
else:
print("correct input")
user_ready = "yes"

if user_ready != "yes" or user_ready != "no":
print("wrong input")
else:
print("correct input")
but it's obviously not going like that. I can't tell you why and this mulberry bush isn't helping. so therefore
JakenVeina
JakenVeina2y ago
you call it a miracle, I call it learning I'm not asking you small leading questions to try to annoy you
Mekasu0124
Mekasu0124OP2y ago
string userReady = "yes";

if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("wrong input");
}
else
{
Console.WriteLine("correct input");
}
string userReady = "yes";

if (userReady != "yes" || userReady != "no")
{
Console.WriteLine("wrong input");
}
else
{
Console.WriteLine("correct input");
}
but it's obviously not doing that
JakenVeina
JakenVeina2y ago
I'm doing it because you WILL get it if you actually go through the effort to answer them
Mekasu0124
Mekasu0124OP2y ago
I know this. Hence me beating myself up instead of blaming you
JakenVeina
JakenVeina2y ago
neither is productive
Mekasu0124
Mekasu0124OP2y ago
I have been giving my best effort but 90% of my answers have been wrong so I just started guessing in hopes that I can get something right. This if statement should be just a simple as what I wrote above in both python and c# but I'm assuming that it's not. I don't know why it's not and I can't answer you on why it's not
JakenVeina
JakenVeina2y ago
which is why I'm helping you break down the problem into questions you CAN answer what does ("yes" != "yes") evaluate to?
Mekasu0124
Mekasu0124OP2y ago
it evaluates to false, but that's what I'm trying to tell you. If the user inputs "yes" then it's supposed to trigger the else part of the if statement. I don't know why it's not
JakenVeina
JakenVeina2y ago
yes, I know
Mekasu0124
Mekasu0124OP2y ago
ok next question
JakenVeina
JakenVeina2y ago
you have told me many times in many different ways what does ("yes" != "no") evaluate to?
Mekasu0124
Mekasu0124OP2y ago
f
JakenVeina
JakenVeina2y ago
f meaning false?
Mekasu0124
Mekasu0124OP2y ago
yes false
JakenVeina
JakenVeina2y ago
why?
Mekasu0124
Mekasu0124OP2y ago
well true because they're not equal
JakenVeina
JakenVeina2y ago
so, what does false || true evaluate to?
Mekasu0124
Mekasu0124OP2y ago
falae false
JakenVeina
JakenVeina2y ago
incorrect
Mekasu0124
Mekasu0124OP2y ago
omg dones it evaluate to null?
JakenVeina
JakenVeina2y ago
"or" evaluates to true when either input is true by definition it only evaluates to false when both inputs are false
Mekasu0124
Mekasu0124OP2y ago
so I need to check if (userReady == "yes" || userReady == "no")
JakenVeina
JakenVeina2y ago
that would be one solution and then invert the actual statement bodies
Mekasu0124
Mekasu0124OP2y ago
what would be another solution?
JakenVeina
JakenVeina2y ago
alternatively, switch || to && cause you don't want "either" you want "neither"
Mekasu0124
Mekasu0124OP2y ago
wow......so simple
JakenVeina
JakenVeina2y ago
it usually is understanding is ALWAYS more difficult and more valuable than just the end result
Mekasu0124
Mekasu0124OP2y ago
you're not wrong, but tbh I still don't fully grasp the difference other than the blatent statement that now || means either and && means neither
JakenVeina
JakenVeina2y ago
well, that's a bit of a misnomer && means "and"
Mekasu0124
Mekasu0124OP2y ago
well I mean yea, but in the context of my check, its either neither
JakenVeina
JakenVeina2y ago
logically what you want is "user input is not yes AND not no" which can be reworded as "neither yes nor no" not yes or not no is a tautology there is literally no input you could ever give that is equal to two different values at the same time any input you give HAS to be not-equal to one of those two, because "yes" and "no" are not equal themselves ergo, no matter what the user inputs, that if statement will always run alternatively it might be simpler to think ofbthe opposite your valid values are either "yes" or "no" so, in order to check for only valid values, you want NOT("yes" OR "no") I.E.
!((userReady == "yes") || (userReady == "no"))
!((userReady == "yes") || (userReady == "no"))
which there is a law for in boolean algebra I forget the name
NOT(A OR B) = NOT(A) AND NOT(B)
NOT(A OR B) = NOT(A) AND NOT(B)
I.E. if you want to invert an expression, you have to invert each term AND invert the operator
Mekasu0124
Mekasu0124OP2y ago
ok I got you. that makes sense
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

Console.Write("\nPlease Select A Game To Play: ");

string userSelectedGame = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (gameTypes.Contains(userSelectedGame.ToLower()))
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
break;
}
else
{
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");
}
}

GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
}
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

Console.Write("\nPlease Select A Game To Play: ");

string userSelectedGame = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (gameTypes.Contains(userSelectedGame.ToLower()))
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
break;
}
else
{
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");
}
}

GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
}
ok so help me understand what I'm doing here please. When I enter addition for my user response, it prints the else statement 3 times then goes to the next function asking me for the number of questions to answer
easy
medium
hard
Please Select A Difficulty: easy

Difficulty: easy


Addition
Subtraction
Multiplication
Division

Please Select A Game To Play: addition
Enter A Game Choice: addition, subtraction, multiplication Or division.
Enter A Game Choice: addition, subtraction, multiplication Or division.
Enter A Game Choice: addition, subtraction, multiplication Or division.

Please Enter The Amount Of Questions You'd Like To Answer (1-100):
easy
medium
hard
Please Select A Difficulty: easy

Difficulty: easy


Addition
Subtraction
Multiplication
Division

Please Select A Game To Play: addition
Enter A Game Choice: addition, subtraction, multiplication Or division.
Enter A Game Choice: addition, subtraction, multiplication Or division.
Enter A Game Choice: addition, subtraction, multiplication Or division.

Please Enter The Amount Of Questions You'd Like To Answer (1-100):
liek that
JakenVeina
JakenVeina2y ago
well I ought to ask you to walk through the code the same way
Mekasu0124
Mekasu0124OP2y ago
oh wait I'm submitting a lower case response "addition" instead of "Addition" so it's causing the error?
JakenVeina
JakenVeina2y ago
well yes and no
Mekasu0124
Mekasu0124OP2y ago
I would say so since I'm casting the check to lower and the list contains capitols
JakenVeina
JakenVeina2y ago
didn't even spot that but that is indeed an issue
Mekasu0124
Mekasu0124OP2y ago
what did you spot?
JakenVeina
JakenVeina2y ago
when does your loop exit?
Mekasu0124
Mekasu0124OP2y ago
if the condition comes true, print the statement of difficulty and game selected then break
JakenVeina
JakenVeina2y ago
(based on the code written) when does the condition evaluate to true?
Mekasu0124
Mekasu0124OP2y ago
when the user enters a game with a capitol first letter
JakenVeina
JakenVeina2y ago
which is in the list
Mekasu0124
Mekasu0124OP2y ago
right
JakenVeina
JakenVeina2y ago
so, it's based on the values of the user input and the list where do those values come from?
Mekasu0124
Mekasu0124OP2y ago
but I don't know how to capitolize the first letter of the user's input incase they do it all lower case the values are in the list
JakenVeina
JakenVeina2y ago
right, where does that come from?
Mekasu0124
Mekasu0124OP2y ago
it's the 4 games available to play for the user to pick from? I'm not sure I'm understanding the question
JakenVeina
JakenVeina2y ago
where is gameTypes given a value? and where does that value change? in particular, relative to where the value is used, within the condition
Mekasu0124
Mekasu0124OP2y ago
in the list at the top of the function those 4 values don't change
JakenVeina
JakenVeina2y ago
how about the user input? userSelectedGame
Mekasu0124
Mekasu0124OP2y ago
it shouldn't be cast to all lower case, and that's my bad on that one, but I'm not sure how to cast an entire list to lower case, and I want them to have capitol letters for pretty printing variable to hold users input
JakenVeina
JakenVeina2y ago
yes, where does it get its value? in code and where does that value change? in code particularly, relative to where it's used, within the condition
Mekasu0124
Mekasu0124OP2y ago
right here string userSelectedGame = Console.ReadLine();
JakenVeina
JakenVeina2y ago
and changes?
Mekasu0124
Mekasu0124OP2y ago
it shouldn't. I removed the to lower cast that I had on the end within the condition but regardless, the users input needs to have a capitol first letter in order to correctly check against the list that much I know
JakenVeina
JakenVeina2y ago
so, if the value never changes, and it controls exiting of the loop, how do you expect the loop to ever exit?
Mekasu0124
Mekasu0124OP2y ago
learn how to capitilize the first letter of the users response, or lowercase the entire list
JakenVeina
JakenVeina2y ago
there's a reason I continue to ignore that whole point it's irrelevant, to this one however you end up testing the input for validity if it's not valid, what do you intend to do?
Mekasu0124
Mekasu0124OP2y ago
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

Console.Write("\nPlease Select A Game To Play: ");

string userSelectedGame = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (gameTypes.Contains(userSelectedGame))
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
Thread.Sleep(2000);

GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
break;
}
else
{
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

Console.Write("\nPlease Select A Game To Play: ");

string userSelectedGame = Console.ReadLine();

for (int i = 0; i < 3; i++)
{
if (gameTypes.Contains(userSelectedGame))
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
Thread.Sleep(2000);

GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
break;
}
else
{
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
ok what about this? no that's worse.
JakenVeina
JakenVeina2y ago
uhhh, if you say so the issue I'm getting at is definitely still present what do you intend to do when the game selection is not valid?
Mekasu0124
Mekasu0124OP2y ago
the else statement
JakenVeina
JakenVeina2y ago
that's the mechanism by which you will execute code to do what you intend to do what do you intend to do?
Mekasu0124
Mekasu0124OP2y ago
I don't know. I guess I just need to lowercase the items in the list that way I can cast the users input to lower to be able to appropriately check against the list. Otherwise I have zero idea
JakenVeina
JakenVeina2y ago
this has nothing to do with uppercase or lowercase or the list
Mekasu0124
Mekasu0124OP2y ago
then please just tell me the issue. I don't have it in me to continuously guess
JakenVeina
JakenVeina2y ago
and it's not, like, a math problem it's your program you tell me what you want it to do when the user enters an invalid game selection assume you have figured out how to deal with the case issue cause you will
Mekasu0124
Mekasu0124OP2y ago
print list to screen enter loop request user input if input in list, break loop continue to next function if not in list, continue loop
JakenVeina
JakenVeina2y ago
well, that's exactly the code you wrote that doesn't REALLY describe what you want to happen when the user enters an invalid game selection
Mekasu0124
Mekasu0124OP2y ago
if not in list, continue loop
JakenVeina
JakenVeina2y ago
at least I'm assuming so again, you're describing code more than function what does the loop do? what does the user see? what does the user do?
Mekasu0124
Mekasu0124OP2y ago
this
JakenVeina
JakenVeina2y ago
is that what you want it to do? (if "addition" was invalid)
Mekasu0124
Mekasu0124OP2y ago
loop and ask again
JakenVeina
JakenVeina2y ago
where is the code for "ask again"?
Mekasu0124
Mekasu0124OP2y ago
the else statement
JakenVeina
JakenVeina2y ago
where in the else statement?
Mekasu0124
Mekasu0124OP2y ago
there is no break statement in the else part of the if statement so therefore it will loop again
JakenVeina
JakenVeina2y ago
so it's not in the else statement? it's at the beginning of the loop? and you're relying on the else to take you back there?
Mekasu0124
Mekasu0124OP2y ago
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

// display list to user
foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

// ask user to pick a game
Console.Write("\nPlease Select A Game To Play: ");
// get user input
string userSelectedGame = Console.ReadLine();
// start loop for chances if input is wrong
for (int i = 0; i < 3; i++)
{
// if list contains users input
if (gameTypes.Contains(userSelectedGame))
{
// tell the user this information
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
// do some fake loading
Thread.Sleep(2000);
// launch next function
GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
// break the loop
break;
}
// if the list does not contain the users input
else
{
// tell the user uh oh
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");

// loop iterates again
}
}

// after 3 tries, program ends
Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GameSelection(string difficulty)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n");

List<string> gameTypes = new()
{
"Addition",
"Subtraction",
"Multiplication",
"Division"
};

// display list to user
foreach (string text in gameTypes)
{
Console.WriteLine(text);
};

// ask user to pick a game
Console.Write("\nPlease Select A Game To Play: ");
// get user input
string userSelectedGame = Console.ReadLine();
// start loop for chances if input is wrong
for (int i = 0; i < 3; i++)
{
// if list contains users input
if (gameTypes.Contains(userSelectedGame))
{
// tell the user this information
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame);
// do some fake loading
Thread.Sleep(2000);
// launch next function
GetDesiredQuestions(difficulty, userSelectedGame.ToLower());
// break the loop
break;
}
// if the list does not contain the users input
else
{
// tell the user uh oh
Console.WriteLine("Enter A Game Choice: addition, subtraction, multiplication" +
" Or division.");

// loop iterates again
}
}

// after 3 tries, program ends
Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
past these comments, I don't know what you want from me. I'm trying my best here
JakenVeina
JakenVeina2y ago
what I want from you is for you to think more about the code you're writing, and its purpose you said your goal is that when the user enters incorrect input, they should be asked for input again
Mekasu0124
Mekasu0124OP2y ago
yes the loop iterates itself up to 3 times without a correct answer
JakenVeina
JakenVeina2y ago
show me the line of code that does that the line of code thst runs to ask the user for input after incorrect input was previously given
Mekasu0124
Mekasu0124OP2y ago
if "the loop iterates itself up to 3 times" isn't the answer, then I guess there isn't one. I don't know is it because my user input line isn't inside the loop
JakenVeina
JakenVeina2y ago
"the loop iterates itself up to 3 times" is a description of how you want this code to work, it is not a line of code yes
Mekasu0124
Mekasu0124OP2y ago
ok great. problem solved. Now onto actually checking against the list correctly
JakenVeina
JakenVeina2y ago
the most proper solution is to use case-insensitive comparison
gameTypes.Contains(userSelectedGame, StringComparer.OrdinalIgnoreCase)
gameTypes.Contains(userSelectedGame, StringComparer.OrdinalIgnoreCase)
Mekasu0124
Mekasu0124OP2y ago
so what's the breakdown for that line. Like how does that help me understand what it's doing?
JakenVeina
JakenVeina2y ago
when calling into code that isn't yours, the first answer to "how does that work" is pretty much always "docs"
Mekasu0124
Mekasu0124OP2y ago
then ill just go to the docs
JakenVeina
JakenVeina2y ago
in short, the .Contains() method does exactly what its name suggests and what you were already using it for
Mekasu0124
Mekasu0124OP2y ago
I know what contains means. I moreso meant the StringComparer.OrginalIgnoreCase part
JakenVeina
JakenVeina2y ago
if you want to adjust the rules for what "equality" means when it is looking for an "equal" value, you give it an object that implements the IEqualityComparer<T> interface I.E. an object that performs equality comparison for .Contains() what you want is for string equality to be not case-sensitive and conveniently, .NET provides a ready-made class that implements IEqualityComparer<T> for exactly that rule as well as a variety of other rules
Mekasu0124
Mekasu0124OP2y ago
ok I got you.
JakenVeina
JakenVeina2y ago
StringComparer.OrdinalIgnoreCase returns an instance of the StringComparer class, which implements IEqualityComparer<string>, for "ordinal and case-insensitive" comparison rules "ordinal" basically meaning "binary ordering and equality" sort of that part is really irrelevant here
Mekasu0124
Mekasu0124OP2y ago
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
if (!int.TryParse(Console.ReadLine(), out int numOfQuestions))
{
Console.WriteLine("Enter An Integer, or Whole Number For Your Choice.");
}
else if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Thread.Sleep(2000);
LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
if (!int.TryParse(Console.ReadLine(), out int numOfQuestions))
{
Console.WriteLine("Enter An Integer, or Whole Number For Your Choice.");
}
else if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Thread.Sleep(2000);
LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
ok so a different use case of a check system. Here I'm checking if the users input is an integer and if it is an integer, then check if it's between 1 and 100. The only reason I'm confused on this one as since we went through the other two is because of the boolean case with trying to parse the input. would I do it similar to the others in the sense of
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
bool isInteger = int.TryParse(Console.ReadLine(), out int numOfQuestions);

if (isInteger)
{
if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Console.WriteLine("\nLaunching Desired Game. Please Wait. . .");
Thread.Sleep(2000);

LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}
else
{
Console.WriteLine("Input Must Be An Integer");
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
bool isInteger = int.TryParse(Console.ReadLine(), out int numOfQuestions);

if (isInteger)
{
if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Console.WriteLine("\nLaunching Desired Game. Please Wait. . .");
Thread.Sleep(2000);

LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}
else
{
Console.WriteLine("Input Must Be An Integer");
}
}

Console.WriteLine("Maximum Number OF Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
i feel like I got this one right
JakenVeina
JakenVeina2y ago
by my reckoning, both of those are equivalent
Mekasu0124
Mekasu0124OP2y ago
what do you mean?
JakenVeina
JakenVeina2y ago
all you did was rearrange the if/else blocks but they're both functionally the same you have three mutually-exclusive scenarios and are executing the same chunks of code for each one
Mekasu0124
Mekasu0124OP2y ago
and I found a problem here. When passing the selected game to the next function, it's not passing it as "addition" or the item in the list so since we used that gameTypes.Contains(userSelectedGame, StringComparer.OrdinalIgnoreCase) for the comparison check, how can I use that to pass the correct game from the list? ok so how can I fix it to be correct?
JakenVeina
JakenVeina2y ago
they're BOTH correct, that's my point both lf those code snippets are functionally correct they are doing functionally the same thing
Mekasu0124
Mekasu0124OP2y ago
well look at me doing something right on accident 😛
JakenVeina
JakenVeina2y ago
I mean, REALLY, the answer is to use an enum but you could get away with using IndexOf() instead of Contains() I THINK that has an overload for an IEqualityComparer
Mekasu0124
Mekasu0124OP2y ago
public void LaunchGameScreen(string difficulty, string game, int numOfQuest)
{
switch (game)
{
case "addition":
Console.WriteLine("\nLaunching Addition Game.");
break;

case "subtraction":
Console.WriteLine("\nLaunching Subtraction Game.");
break;

case "multiplication":
Console.WriteLine("\nLaunching Multiplication Game.");
break;

case "division":
Console.WriteLine("\nLaunching Division Game.");
break;

default:
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Invalid Operation Launching Desired Game. Trying Again. . .");
Thread.Sleep(2000);
LaunchGameScreen(difficulty, game, numOfQuest);
}
Console.WriteLine("Number Of Attempts Reached. Default Back To Previous Screen.");

Program program = new();
program.WelcomeLabel();
break;
}
}
public void LaunchGameScreen(string difficulty, string game, int numOfQuest)
{
switch (game)
{
case "addition":
Console.WriteLine("\nLaunching Addition Game.");
break;

case "subtraction":
Console.WriteLine("\nLaunching Subtraction Game.");
break;

case "multiplication":
Console.WriteLine("\nLaunching Multiplication Game.");
break;

case "division":
Console.WriteLine("\nLaunching Division Game.");
break;

default:
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Invalid Operation Launching Desired Game. Trying Again. . .");
Thread.Sleep(2000);
LaunchGameScreen(difficulty, game, numOfQuest);
}
Console.WriteLine("Number Of Attempts Reached. Default Back To Previous Screen.");

Program program = new();
program.WelcomeLabel();
break;
}
}
because right now the problem is that this function just jumps straight to the end thing of cancelling the application
easy
medium
hard
Please Select A Difficulty: easy

Difficulty: easy


Addition
Subtraction
Multiplication
Division

Please Select A Game To Play: addition

Difficulty: easy
Game: addition

Please Enter The Amount Of Questions You'd Like To Answer (1-100): 5

Difficulty: easy
Game: addition
Questions: 5

Launching Addition Game.
Maximum Number OF Attempts Reached. Exiting Program. . .

C:\Users\Mekas\Documents\my_projects\VisualStudioProjects\DesktopApps\MeksMathGame\bin\Debug\net6.0\MeksMathGame.exe (process 7572) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
easy
medium
hard
Please Select A Difficulty: easy

Difficulty: easy


Addition
Subtraction
Multiplication
Division

Please Select A Game To Play: addition

Difficulty: easy
Game: addition

Please Enter The Amount Of Questions You'd Like To Answer (1-100): 5

Difficulty: easy
Game: addition
Questions: 5

Launching Addition Game.
Maximum Number OF Attempts Reached. Exiting Program. . .

C:\Users\Mekas\Documents\my_projects\VisualStudioProjects\DesktopApps\MeksMathGame\bin\Debug\net6.0\MeksMathGame.exe (process 7572) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
or is it doing that because I don't have something right in another function?
JakenVeina
JakenVeina2y ago
no, your assessment is right
Mekasu0124
Mekasu0124OP2y ago
after messing around with the print statements of "Maximum Number Of Attempts Reached. Exiting Program. . ." I have determined that the issue is in this function
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
if (!int.TryParse(Console.ReadLine(), out int numOfQuestions))
{
Console.WriteLine("Enter An Integer, or Whole Number For Your Choice.");
}
else if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Thread.Sleep(2000);
LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}

Console.WriteLine("Maximum Number Of Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GetDesiredQuestions(string difficulty, string userSelectedGame)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("\nPlease Enter The Amount Of Questions You'd Like To Answer (1-100): ");

for (int i = 0; i < 3; i++)
{
if (!int.TryParse(Console.ReadLine(), out int numOfQuestions))
{
Console.WriteLine("Enter An Integer, or Whole Number For Your Choice.");
}
else if (numOfQuestions < 1 || numOfQuestions > 100)
{
Console.WriteLine("Enter A Number Between 1 and 100");
}
else
{
Console.WriteLine("\nDifficulty: " + difficulty + "\nGame: " + userSelectedGame + "\nQuestions: " + numOfQuestions);
Thread.Sleep(2000);
LaunchGameScreen(difficulty, userSelectedGame, numOfQuestions);
break;
}
}

Console.WriteLine("Maximum Number Of Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
JakenVeina
JakenVeina2y ago
as in, that's the Environment.Exit(0) call that's being hit?
Mekasu0124
Mekasu0124OP2y ago
right like I enter a number for the number of questions to be answered, it accepts it, triggers the appropriate print statement in the LaunchGameScreen function, but then continues the loop and errors out after the fact instead of breaking the loop
JakenVeina
JakenVeina2y ago
breaking what loop? the one in GetDesiredQuestions or in LaunchGameScreen?
Mekasu0124
Mekasu0124OP2y ago
Launching Addition Game. Maximum Number OF Attempts Reached. Exiting Program. . . C:\Users\Mekas\Documents\my_projects\VisualStudioProjects\DesktopApps\MeksMathGame\bin\Debug\net6.0\MeksMathGame.exe (process 7572) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .
like here, it accepts my number for number of questions to be answered, goes to the next function of launching the corresponding game screen for the game being selected Launching Addition Game but instead of stopping after the print statement, it's going back into the GetDesiredQuestions function and triggering the environment exit part
JakenVeina
JakenVeina2y ago
yes, exactly why would it stop?
Mekasu0124
Mekasu0124OP2y ago
I would guess it's because the loop doesn't break when it triggers the next function, it pauses instead with the way we've been setting this up, the loops don't technically break, but pause instead because of the next function call before the break statement
JakenVeina
JakenVeina2y ago
where is the line of code that is going to cause "it" to stop? that's fair to say
Mekasu0124
Mekasu0124OP2y ago
ok so for example
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");


for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();

if (userReady != "yes" && userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

Environment.Exit(0);
break;
}
}
}

Console.WriteLine("Maximum Number Of Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");


for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();

if (userReady != "yes" && userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

Environment.Exit(0);
break;
}
}
}

Console.WriteLine("Maximum Number Of Attempts Reached. Exiting Program. . .");
Thread.Sleep(2000);
Environment.Exit(0);
}
when this condition renders true that "yes" has been answered, it's supposed to break the loop and go to the next function, but instead, it's pausing the loop and going to the next function so when that next function, in this case the LaunchGameScreen, reaches the end of it's code line, or error out, it goes back to that paused loop and then breaks and exits the environment when in reality it shouldn't be pausing the loop. It should be stopping/breaking the loop and continuing the loop is only there to give the user another chance at entering the correct answer. Once the correct answer is given, the loop shouldn't exist anymore
JakenVeina
JakenVeina2y ago
yes, that is what's happening
Mekasu0124
Mekasu0124OP2y ago
ok so I've got my structure wrong for this whole thing
JakenVeina
JakenVeina2y ago
"wrong" is relative if it's not what you wanted, it's not what you wanted it certainly COULD be made to work
Mekasu0124
Mekasu0124OP2y ago
true. I'm just trying to think of how it needs to be written to give me what it's supposed to be doing instead of what it's currently doing it could but then I'll have a program full of paused loops and I don't want that
JakenVeina
JakenVeina2y ago
well, it's rather straightforwards that's not nearly as insane as you make it sound
Mekasu0124
Mekasu0124OP2y ago
and it may not be, but I just don't know if that would be efficient
JakenVeina
JakenVeina2y ago
that's... how call stacks work
Mekasu0124
Mekasu0124OP2y ago
if that's the correct term
JakenVeina
JakenVeina2y ago
I would say it's not well-orgaized that's an opinion, but I think O can safely say most folks here would agree
Mekasu0124
Mekasu0124OP2y ago
ok so walk with me here. If I were to take where I call the next function before the break statement and put it outside the for loop, then where would I tell the for loop to exit the program after 3 tries?
JakenVeina
JakenVeina2y ago
you do as well, you just don't have the wisdom to put into words what's undesirable about it like I said, it's rather straightforward you already said it yourself you want the loop to break before you call the next function so you need to do literally that cause right now you have
NextFunction();
break;
NextFunction();
break;
Mekasu0124
Mekasu0124OP2y ago
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");
for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();
if (userReady != "yes" && userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();
Environment.Exit(0);
break;
}
}
}
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();
MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");
for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();
if (userReady != "yes" && userReady != "no")
{
Console.WriteLine("Enter Either yes To Start Or no To Exit.");
}
else
{
if (userReady == "yes")
{
break;
}
else if (userReady == "no")
{
Console.WriteLine("\nExiting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();
Environment.Exit(0);
break;
}
}
}
Console.WriteLine("\nStarting Game. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();
MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
this will break and then call the next function, but now I have no where to tell the program to exit after 3 tries of incorrect answers
JakenVeina
JakenVeina2y ago
loop(condition)
{
if(condition)
break;
}
NextFunction();
loop(condition)
{
if(condition)
break;
}
NextFunction();
Mekasu0124
Mekasu0124OP2y ago
right, but either way, after 3 tries that NextFunction(); is going to be called once the loop finishes
JakenVeina
JakenVeina2y ago
this is indeed correct so, you need to be able to detect HOW the loop exited
Mekasu0124
Mekasu0124OP2y ago
ok I'm listening
JakenVeina
JakenVeina2y ago
cause it can exit multiple ways and what you do next depends on which one or stick with what you have, and maybe just clean up the semantics
Mekasu0124
Mekasu0124OP2y ago
well before I tired doing this with loops, I had this
JakenVeina
JakenVeina2y ago
you had callback delegates, yes? that's not a terrible approach
Mekasu0124
Mekasu0124OP2y ago
static void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");
string userReady = Console.ReadLine();

// instantiate a tries variable for else statement
int tries = 3;

if (userReady.ToLower() == "yes")
{
Console.WriteLine("Launching Main Menu...");
Thread.Sleep(3000);
Console.Clear();

MainMenu mainMenu = new MainMenu();
mainMenu.DifficultySelection();
}
else if (userReady.ToLower() == "no")
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Exiting Game. Please Wait.");
Thread.Sleep(2000);
Environment.Exit(0);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(
"Invalid Operation. Please Enter 'Yes' To Start The Game" +
"or Enter 'No' To Exit The Game."
);
Thread.Sleep(1000);

// decrement tries by 1
tries--;
// if tries is greater than 0
if (tries > 0)
{
// allow the user to try again
GetUserInput();
}
else
{
// otherwise, exit the program to prevent unecessary loop
Environment.Exit(0);
}
}
}
static void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'Yes' To Start, Or 'No' To Exit.\n");
string userReady = Console.ReadLine();

// instantiate a tries variable for else statement
int tries = 3;

if (userReady.ToLower() == "yes")
{
Console.WriteLine("Launching Main Menu...");
Thread.Sleep(3000);
Console.Clear();

MainMenu mainMenu = new MainMenu();
mainMenu.DifficultySelection();
}
else if (userReady.ToLower() == "no")
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Exiting Game. Please Wait.");
Thread.Sleep(2000);
Environment.Exit(0);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(
"Invalid Operation. Please Enter 'Yes' To Start The Game" +
"or Enter 'No' To Exit The Game."
);
Thread.Sleep(1000);

// decrement tries by 1
tries--;
// if tries is greater than 0
if (tries > 0)
{
// allow the user to try again
GetUserInput();
}
else
{
// otherwise, exit the program to prevent unecessary loop
Environment.Exit(0);
}
}
}
JakenVeina
JakenVeina2y ago
if I were to really workshop this myself, I would probably do something with callbacks
Mekasu0124
Mekasu0124OP2y ago
this is what I had before, but I was trying to clean my code up and not make it so elongated
JakenVeina
JakenVeina2y ago
still looping, but recursive essentially
Mekasu0124
Mekasu0124OP2y ago
in your honest opinion, should I go back to that?
JakenVeina
JakenVeina2y ago
not that, no
Mekasu0124
Mekasu0124OP2y ago
I'm ngl. I don't know how to do callbacks, or at least I don't think I do
JakenVeina
JakenVeina2y ago
but the whole deal that started this thread? probably something like that
Mekasu0124
Mekasu0124OP2y ago
so helper functions
public int tries = 3;

public void InputInvalid(string error)
{
if (tries > 0)
{
tries--;
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
}
else
{
Console.WriteLine("\nMaximum Number Attempts Reached. Exiting Program.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}

public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'yes' To Start, Or 'no' To Exit.\n");


for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();

if (userReady == "yes")
{
break;
}
else if (userReady == "no")
{
Environment.Exit(0);
}
else
{
InputInvalid("Enter yes To Begin Or no To Exit");
}
}

Console.WriteLine("\nLaunching Difficulty Selection. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
public int tries = 3;

public void InputInvalid(string error)
{
if (tries > 0)
{
tries--;
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
}
else
{
Console.WriteLine("\nMaximum Number Attempts Reached. Exiting Program.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}

public void GetUserInput()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("When You Are Ready To Begin, Enter 'yes' To Start, Or 'no' To Exit.\n");


for (int i = 0; i < 3; i++)
{
string userReady = Console.ReadLine().ToLower();

if (userReady == "yes")
{
break;
}
else if (userReady == "no")
{
Environment.Exit(0);
}
else
{
InputInvalid("Enter yes To Begin Or no To Exit");
}
}

Console.WriteLine("\nLaunching Difficulty Selection. Please Wait. . .");
Thread.Sleep(2000);
Console.Clear();

MainMenu mainMenu = new();
mainMenu.DifficultySelection();
}
like that then? fixed it fixed it again lol wrong call at the end of the loop
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
going with that methodology, in this instance, userSelectedDiff at the bottom is not reachable as it's not in the same scope, so how would I get access to it?
JakenVeina
JakenVeina2y ago
public abstrsct class UserPrompt<T>
{
public int MaxFailureCount { get; init; }
= 3;

public bool TryExecute(out T result)
{
for(var failureCount = 0; failureCount < MaxFailureCount; ++failureCount)
if(OnExecuteTrying(result))
return true;

Console.WriteLine("Exceeded maximum tries. Exiting.");
return false;
}

protected abstract bool OnExecuteTrying(out T result);
}

public sealed class UserReadyPrompt
: UserPrompt<bool>
{
protected override bool OnExecuteTrying(out bool result)
{
Console.WriteLine("Enter yes To Begin Or no To Exit");
var userInput = Console.ReadLine();

result = userInput.Equals("yes", StringComparison.OrdinalIgnoreCase);
return result || userInput.Equals("no", StringComparison.OrdinalIgnoreCase);
}

public void Main()
{
if(!(new UserReadyPrompt.TryExecute(out var isUserReady)))
return;

if(!isUserReady)
{
Console.WriteLine("User not ready. Exiting.");
return;
}

if(!(new GameSelectionPrompt().TryExecute(out var gameSelection))
return;

if(!(new QuestionCountPrompt().TryExecute(out var questionCont))
return;

...
}
public abstrsct class UserPrompt<T>
{
public int MaxFailureCount { get; init; }
= 3;

public bool TryExecute(out T result)
{
for(var failureCount = 0; failureCount < MaxFailureCount; ++failureCount)
if(OnExecuteTrying(result))
return true;

Console.WriteLine("Exceeded maximum tries. Exiting.");
return false;
}

protected abstract bool OnExecuteTrying(out T result);
}

public sealed class UserReadyPrompt
: UserPrompt<bool>
{
protected override bool OnExecuteTrying(out bool result)
{
Console.WriteLine("Enter yes To Begin Or no To Exit");
var userInput = Console.ReadLine();

result = userInput.Equals("yes", StringComparison.OrdinalIgnoreCase);
return result || userInput.Equals("no", StringComparison.OrdinalIgnoreCase);
}

public void Main()
{
if(!(new UserReadyPrompt.TryExecute(out var isUserReady)))
return;

if(!isUserReady)
{
Console.WriteLine("User not ready. Exiting.");
return;
}

if(!(new GameSelectionPrompt().TryExecute(out var gameSelection))
return;

if(!(new QuestionCountPrompt().TryExecute(out var questionCont))
return;

...
}
Mekasu0124
Mekasu0124OP2y ago
🤯 like boy. that couldn't be more above my head than an airplane in the sky
JakenVeina
JakenVeina2y ago
honestly, mostly the same concept as the callback idea, but implemented with inheritance instead ends up being cleaner, I think
Mekasu0124
Mekasu0124OP2y ago
yours or mine? lol
JakenVeina
JakenVeina2y ago
the callback is the OnExecuteTrying() method
Mekasu0124
Mekasu0124OP2y ago
mine is with inheritence, yea?
JakenVeina
JakenVeina2y ago
that TryExecute() calls uhhhhh, no there is no inheritance anywhere in your code but, like, your original thought was to dedupe code your peril was that you couldn't adequately identify whatnitbwas you were wanting to do, and what you wanted to dedupe
Mekasu0124
Mekasu0124OP2y ago
I mean yea, but what you wrote completely threw me out the ball game. I wouldn't have any idea what to write with that, where to put it, or how to use it
JakenVeina
JakenVeina2y ago
what you really WANT here or at least, what you have the opportunity for, is to dedupe the logic you have repeated for retrieving user input
Mekasu0124
Mekasu0124OP2y ago
did you even see my attempt? lol I'm like a 1st grader and you're in the master's program lmao I can't even get access to my own variable
JakenVeina
JakenVeina2y ago
in particular, the logic for retrying the same user prompt until they get it right, or run out of tries that can absolutely be deduped if callbacks make more sense, we can go with that
Mekasu0124
Mekasu0124OP2y ago
public int tries = 3;

public void InputInvalid(string error)
{
if (tries > 0)
{
tries--;
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
}
else
{
Console.WriteLine("\nMaximum Number Attempts Reached. Exiting Program.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}

public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
public int tries = 3;

public void InputInvalid(string error)
{
if (tries > 0)
{
tries--;
Console.WriteLine("\n" + error + " " + tries + " Tries Left.");
}
else
{
Console.WriteLine("\nMaximum Number Attempts Reached. Exiting Program.");
Thread.Sleep(2000);
Environment.Exit(0);
}
}

public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
idk if this is callbacks or not, but what I wrote here makes sense to me. I just can't get access to my own variable outside of the for loop
JakenVeina
JakenVeina2y ago
which one?
Mekasu0124
Mekasu0124OP2y ago
string userSelectDiff = Console.ReadLine(); it tells me that in line Console.WriteLine("\nDifficulty: " + userSelectDiff); doesn't exist within this context
JakenVeina
JakenVeina2y ago
indeed
Mekasu0124
Mekasu0124OP2y ago
I tried doing public string userSelectDiff; but it didn't like that at all
JakenVeina
JakenVeina2y ago
yes, that would be invalid syntax
Mekasu0124
Mekasu0124OP2y ago
ok so learn me ObiWan lol
JakenVeina
JakenVeina2y ago
you defined it inside the scope of the for loop, so it only exists inside the scope of the for loop
Mekasu0124
Mekasu0124OP2y ago
well doing
string userSelectedDiff;
for ()
{
userSelectedDiff = Console.ReadLine();
}
string userSelectedDiff;
for ()
{
userSelectedDiff = Console.ReadLine();
}
just cause a whole bunch of red lines so I'm not understanding
JakenVeina
JakenVeina2y ago
what red lines? cause that is exactly what you want
Mekasu0124
Mekasu0124OP2y ago
string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine(); // doens't exist in this context

if (gameDiffs.Contains(userSelectDiff)) // doesn't exist in this context
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff); // doesn't exist in this context
Thread.Sleep(2000);

GameSelection(userSelectDiff); // doesn't exist in this context
}
string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine(); // doens't exist in this context

if (gameDiffs.Contains(userSelectDiff)) // doesn't exist in this context
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff); // doesn't exist in this context
Thread.Sleep(2000);

GameSelection(userSelectDiff); // doesn't exist in this context
}
JakenVeina
JakenVeina2y ago
uhh yeah what is userSelectDiff? that doesn't exist in ANY context
Mekasu0124
Mekasu0124OP2y ago
I don't know. I tried to instantiate it outside of the for loop so that the bottom code could have access to it. I honestly don't know
JakenVeina
JakenVeina2y ago
well, you wrote it what is userSelectDiff?
Mekasu0124
Mekasu0124OP2y ago
user input
JakenVeina
JakenVeina2y ago
in code
Mekasu0124
Mekasu0124OP2y ago
the variable that holds the console read line to prompt for user input
JakenVeina
JakenVeina2y ago
k where is that variable defined?
Mekasu0124
Mekasu0124OP2y ago
inside the for loop for proper calling when the input is wrong
JakenVeina
JakenVeina2y ago
show me the line of code
Mekasu0124
Mekasu0124OP2y ago
what do you mean? it's right there a few messages up
JakenVeina
JakenVeina2y ago
it is, in fact, not which line do you THINK is the definition for that variable?
Mekasu0124
Mekasu0124OP2y ago
right here is the code
JakenVeina
JakenVeina2y ago
yes, I am aware of the code you wrote
Mekasu0124
Mekasu0124OP2y ago
ok so the variable userSelectedDiff is in that code block right there, first line inside the for loop I don't know what else you want me to say other than to copy that single line and repost it when it's already right there
JakenVeina
JakenVeina2y ago
yes, do that also, pick which block of code we're talking about because I thought we were talking about the one you posted with the errors notated but that's not what you linked me to
Mekasu0124
Mekasu0124OP2y ago
this one is the same as https://discordapp.com/channels/143867839282020352/1112207639976345600/1112306053984550912 <- this one. The only difference is, this one (hyper link) is a small snippet of the replied to one. apologies
JakenVeina
JakenVeina2y ago
great
Mekasu0124
Mekasu0124OP2y ago
that's my bad. didn't realize we we're on two separate pages. sorry
JakenVeina
JakenVeina2y ago
which line do you think defines the userSelectDiff variable? paste it
Mekasu0124
Mekasu0124OP2y ago
^
JakenVeina
JakenVeina2y ago
that line does not appear in the snippet
Mekasu0124
Mekasu0124OP2y ago
well no duh. In the snippet is where I tried to instantiate the variable outside of the for loop as stated here https://discordapp.com/channels/143867839282020352/1112207639976345600/1112306520814792798
JakenVeina
JakenVeina2y ago
yes and that snippet has errors errors telling you thst userSelectDiff is not defined in that snippet because it's not
Mekasu0124
Mekasu0124OP2y ago
yes. that's what I've been trying to solve
JakenVeina
JakenVeina2y ago
so, why, when I asked you which line from that snippet do you think defines the variable, are you giving me lines not in that snippet?
Mekasu0124
Mekasu0124OP2y ago
because as I stated here
JakenVeina
JakenVeina2y ago
so are we trying to solve the errors in the snippet that contains errors, or not?
Mekasu0124
Mekasu0124OP2y ago
ok so as my friend stated, this a chess game for us. Neither of us know each other, and you don't know my experience with this language. I have only been doing C# for like maybe a week now. I'm used to working in higher level languages such as Python and JavaScript. This is all brand new to me working in a lower level language such as C#. I'm not trying to be an asshole and I'm sorry If I'm coming off that way, but none of this shit makes any sense to me when it should make all the sense in the world. I apologize for my part I'm just trying to get the code outside of the loop to have access to the userSelectedDiff value
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

for (int i = 0; i < 3; i++)
{
string userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
how this currently sits, I cannot pass the selected difficulty to the next function
JakenVeina
JakenVeina2y ago
alright yes we already determined this you proposed a solution and I told you it was the correct solution move the variable definition outside the loop you said it had errors so we need to solve those errors
JakenVeina
JakenVeina2y ago
yes there is no need for you to apologize for things you don't know the only thing you need is focus which is irrelevant of what languages you do or don't know the question stands in that snippet
Mekasu0124
Mekasu0124OP2y ago
ok so moving the variables instantiation outside of the for loop causes a lot of undefined errors. How can I solve that
JakenVeina
JakenVeina2y ago
the snippet with errors
Mekasu0124
Mekasu0124OP2y ago
yes
JakenVeina
JakenVeina2y ago
the errors are telling you that userSelectDiff is not defined
Mekasu0124
Mekasu0124OP2y ago
correct in that context
JakenVeina
JakenVeina2y ago
where is the line that you think should define it? in that snippet the one with the errors this one
string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine(); // doens't exist in this context

if (gameDiffs.Contains(userSelectDiff)) // doesn't exist in this context
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff); // doesn't exist in this context
Thread.Sleep(2000);

GameSelection(userSelectDiff); // doesn't exist in this context
}
string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine(); // doens't exist in this context

if (gameDiffs.Contains(userSelectDiff)) // doesn't exist in this context
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff); // doesn't exist in this context
Thread.Sleep(2000);

GameSelection(userSelectDiff); // doesn't exist in this context
}
Mekasu0124
Mekasu0124OP2y ago
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
public void DifficultySelection()
{
Console.ForegroundColor = ConsoleColor.White;

List<string> gameDiffs = new()
{
"easy",
"medium",
"hard"
};

foreach (string text in gameDiffs)
{
Console.WriteLine(text);
};

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please Select A Difficulty: ");

string userSelectedDiff;

for (int i = 0; i < 3; i++)
{
userSelectDiff = Console.ReadLine();

if (gameDiffs.Contains(userSelectDiff))
{
break;
}
else
{
InputInvalid("Enter Either easy, medium, or hard");
}
}

Console.WriteLine("\nDifficulty: " + userSelectDiff);
Thread.Sleep(2000);

GameSelection(userSelectDiff);
}
This is having it defined outside of the for loop with the errors so I don't have to keep scrolling up
JakenVeina
JakenVeina2y ago
k
Mekasu0124
Mekasu0124OP2y ago
I don't know unless it is in the class as a public variable but that doesn't seem right to me
JakenVeina
JakenVeina2y ago
so you wrote code that references a variable named userSelectDiff and you never considered that you need to define it
Mekasu0124
Mekasu0124OP2y ago
tbh I thought string userSelectedDiff; did define the variable.
JakenVeina
JakenVeina2y ago
no, that defines userSelectedDiff also when I asked "what line of code do you think defines it" ^ you in fact DID know the answer as you should you are the only one that can tell me what you think
Mekasu0124
Mekasu0124OP2y ago
because when I said that, you said "references a variable" and that I "never considered that I needed to define it" so I didn't know that string userSelectedDiff; defined it I thought it referenced it or am I just lost again
JakenVeina
JakenVeina2y ago
apparently you are, because just a moment ago, you said you thought that line defined it now you're saying you thought that line referenced it regardless
string userSelectedDiff;
string userSelectedDiff;
defines a local method variable named userSelectedDiff of type string it tells the compiler that it exists, and what it's scope is you then proceed to never use this variable at the same time, you are repeatedly referencing something named userSelectDiff that has not been defined in any scope
Mekasu0124
Mekasu0124OP2y ago
I've got about 15 more minutes for this to make sense or I'm just giving up with C# altogether. This language shouldn't be this hard
JakenVeina
JakenVeina2y ago
this has UTTERLY nothing to do with C#
Mekasu0124
Mekasu0124OP2y ago
if I defined it, but never used it, then what does userSelectDiff = Console.ReadLine(); inside the for loop of the snippet mean then
JakenVeina
JakenVeina2y ago
that is you reading user input from the console and attempting to store it into something named userSelectDiff which has not been defined
Mekasu0124
Mekasu0124OP2y ago
then how does it need to be defined?
JakenVeina
JakenVeina2y ago
how do you want to define it? like what do you want it to be? and what type?
Mekasu0124
Mekasu0124OP2y ago
the code outside the for loop just needs access to it that simple
JakenVeina
JakenVeina2y ago
right so, you want it to be a local variable outside of the loop
Mekasu0124
Mekasu0124OP2y ago
sure
JakenVeina
JakenVeina2y ago
what type?
Mekasu0124
Mekasu0124OP2y ago
whatever type gives the code outside that for loop access to it
JakenVeina
JakenVeina2y ago
type has nothing to do with accessibility what value do you want to store in it? what does Console.ReadLine() return?
Mekasu0124
Mekasu0124OP2y ago
my guy, how do I need to write that variable outside of that for loop so that the user prompt can get the user input and the code outside that for loop can access that input
JakenVeina
JakenVeina2y ago
what type do you want the variable to be?
Mekasu0124
Mekasu0124OP2y ago
whatever type gives the code outside that for loop access to it
JakenVeina
JakenVeina2y ago
type has nothing to do with accessibility
Mekasu0124
Mekasu0124OP2y ago
then don't ask me what type do I want it to be
JakenVeina
JakenVeina2y ago
I have to you can't define a variable without knowing its type a variable definition consists of three things its name, its type, and its scope we know what name you want we know what scope you want what type do you want? what type does Console.ReadLine() return?
Mekasu0124
Mekasu0124OP2y ago
if before it was a string when defined inside the loop, what makes you think that's going to change? It's a string. It's obtaining a string. It is a variable to hold a string
JakenVeina
JakenVeina2y ago
so string that's all the pieces
Mekasu0124
Mekasu0124OP2y ago
you already knew that
JakenVeina
JakenVeina2y ago
I did
Mekasu0124
Mekasu0124OP2y ago
jesus take the wheel
JakenVeina
JakenVeina2y ago
what's the syntax for defining a variable?
Mekasu0124
Mekasu0124OP2y ago
you tell me
JakenVeina
JakenVeina2y ago
do you think it's changed since the last time you wrote a variable definiton?
JakenVeina
JakenVeina2y ago
Variables - C# language specification
This chapter covers variable categories, default values, definite assignment, and variable references.
JakenVeina
JakenVeina2y ago
variable_type variable_name;
variable_type variable_name;
so, what's the syntax for defining a variable named userSelectDiff of type string?
Mekasu0124
Mekasu0124OP2y ago
nope. it hasn't changed. Just tired of feeling stupid and like I'm going around circles because you continuously want me to answer questions that we both already know the answer to just because you call it learning. Like I'm good. If you won't show me a code example to visibly show me what I'm doing wrong with a simple explanation, then I'm no longer interested. I don't want the answer handed to me, but I'm not going to continue to feel like I'm going in circles of something simple or what could be simple. I know how to instantiate a variable. You already know I know how to do that so it's pointless to ask me again. You already know that the variable is holding a string but yet you asked me again. Like don't do that. Either show me an example with an explanation or I'm just done. I'm tired of feeling stupid and I'm tired of circles
JakenVeina
JakenVeina2y ago
the only reason we're going in circles is that you keep sending us there
Mekasu0124
Mekasu0124OP2y ago
yep my fault. thanks. good night
JakenVeina
JakenVeina2y ago
you say you know how to define a variable, and yet I told you a long time ago that your definition was wrong
Mekasu0124
Mekasu0124OP2y ago
ok
JakenVeina
JakenVeina2y ago
you say you don't want to be handed the answer, and yet when I break the problem down into small steps that you can use to get to the answer, you'd rather complain about it
Mekasu0124
Mekasu0124OP2y ago
again my fault. cool beans
JakenVeina
JakenVeina2y ago
there's a difference between being at fault for not knowing something (which is never valid) and being at fault for not being willing to think for yourself the reason I ask you to answer small simple questions is that you A) can B) should eventually be able to ask them for yourself, on your own, and C) will ALWAYS remember things better by doing, rather than simply being shown earlier, when the question was "how do I deal with uppercase in the user's input" I didn't go through this I straight up gave you the answer and linked you to docs
Mekasu0124
Mekasu0124OP2y ago
well I no longer understand what you want from me. I have tried answering your questions only to be wrong 100 times. I've tried giving my best shot and yet here we are multiple hours and have yet to move off the first 2 files of the program. Apparently it is my fault if all I'm doing is complaining. So it's cool. I can just as easily go back to a language I know and achieve the same thing. I'm learning this language to simply have another language under my belt but I can so much more easily create the same game in the other languages I know so again, it's cool.
JakenVeina
JakenVeina2y ago
because it wasn't about taking knowledge you already have and learning to apply it, it was about the existence of library code you have no knowledge of and again, THIS problem has nothing to do with the language
Mekasu0124
Mekasu0124OP2y ago
ok
JakenVeina
JakenVeina2y ago
variables exist in Python and JavaScript, and are defined the same way, save for types
Mekasu0124
Mekasu0124OP2y ago
yep
JakenVeina
JakenVeina2y ago
you are attempting to use a variable named userSelectDiff which you have never defined you want it to be a string and have scope outside of the for loop the syntax for that is
string userSelectDiff;
string userSelectDiff;
put that outside of your for loop
Mekasu0124
Mekasu0124OP2y ago
if you will look at this god blessed code block, you will see that I did that! I've been done that! That's what is causing the errors for the rest of the variables usage inside and outside of the for loop!
JakenVeina
JakenVeina2y ago
you, in fact, have not what you have is
string userSelectedDiff;
string userSelectedDiff;
Mekasu0124
Mekasu0124OP2y ago
oh this has to be a joke. Do explain what the difference's outcome is going to be before I lose it
JakenVeina
JakenVeina2y ago
userSelectDiff and userSelectedDiff are not the same
Mekasu0124
Mekasu0124OP2y ago
I'm not that slow so again, please expaling what the differences outcome is going to be
JakenVeina
JakenVeina2y ago
uhm well
Mekasu0124
Mekasu0124OP2y ago
what is it going to do with removing the ed from my variable outside the loop going to help with the variable inside the loop
JakenVeina
JakenVeina2y ago
when you change userSelectedDiff to userSelectDiff, the variable userSelectDiff will be defined and the code will compile because the compiler will know what userSelectDiff is when you refer to it inside the loop
Mekasu0124
Mekasu0124OP2y ago
if you would have simply stated that my variables had different names AT THE START of this, we could have avoided every single bit of this. I'm not remedial and that would have made IMMEDIATE since.
JakenVeina
JakenVeina2y ago
and because it is defined outside the loop, your code later on after the loop will also be able to refer ot it
Mekasu0124
Mekasu0124OP2y ago
this is what I'm talking about. going in circles over something simple. It would have been a simple response to just say "it cant get access to it because the variables don't have the same name" see how simple that is and so easy to understand instead of having to answer all those questions like a remedial toddler that simple I'm done at this point. Like I'm done
JakenVeina
JakenVeina2y ago
the fact that you were willing to spend 2 hours arguing with a stranger without any effort to inspect your own code for yourself for trivial errors shows that you needed more than just me pointing out a typo
sokopa
sokopa2y ago
Mekasu, ReactiveVeina was trying to make you ask the questions yourself to see what the problem is. You were not open to help at all. Reactive has been VERY patient in this lengthy thread. Sorry for intervening like this
JakenVeina
JakenVeina2y ago
I ask you small trivial questions because those are the questions you will ultimately be capable of asking for yourself
Mekasu0124
Mekasu0124OP2y ago
so it's my fault that they couldn't have just said the variable names didn't match you're joking
JakenVeina
JakenVeina2y ago
because those are the questions I asked myself to spot the error
sokopa
sokopa2y ago
You dismissed every question and didnt take a second look, you would have seen the error if you asked the question yourself. Also, what IDE are you using? Something like this would show up
Mekasu0124
Mekasu0124OP2y ago
the fact that you were willing to entertain a 2 hour long arguement that could have easily been avoided with a simple "you have a typo" or something relative to it just shows immaturity. I do get that you have been patient with me, and for that I appreciate you, but to have all of that happen when it could have been avoided with a simple statement is just....wow..... and it's not that I "didn't take a second to look". It's the fact that it was a small oversight for me, but I guess that accounts for nothing because it doesn't matter what I say in my defense, it just going to continue to circle back to being my fault. This is why I stopped asking for help in the first place and never should have come here for help either because no matter what its always my fault so I'm good. I no longer care at this point and I won't be reading any further responses unless I'm forced to.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server