+ 2

would someone help me with my visual studio c# code please?

So I'm using c# visual studio to create a code that will generate a random question when one hits the button, and when one hits another button, the answer to that question will be generated. My problem is that i am having trouble defining a random integer that will work for both buttons. From what I am gathering on the internet, C# doesnt have global variables that can be accessed by both of my buttons. Right now, my approach was to generate a random integer, and depending on that integer have question 1 generate, and then when they click the Show Answer button have answer 1 generate. But if anyone has any ideas on how I might make the question / answer work, I would be very grateful. While it wont run on sololearn, i will still post what code i do have. https://code.sololearn.com/c9OM3cONbJdf/?ref=app Edit: Thanks guys! It works now!

23rd Mar 2019, 6:31 PM
Kav
Kav - avatar
5 Answers
+ 3
You can try passing the number into a function as an argument.
23rd Mar 2019, 7:00 PM
Jan Ơtěch
Jan Ơtěch - avatar
+ 3
~ swim ~ i tried to do that, but i think i did it wrong. what do i put before it? private static class? Jan Ơtěch i didnt think of a function. ill try that too. thanks
25th Mar 2019, 11:49 PM
Kav
Kav - avatar
+ 2
~ swim ~ ok thanks!
26th Mar 2019, 7:29 PM
Kav
Kav - avatar