You don't have any methods defined but you need to know the convention. So, in your code: playeranswer becomes playerAnswer, and so on. Net convention is to use PascalCase for methods and classes and the like, and camelCase for variables. I think it is better to have declaration and assignment in one line, it is terser and more readable: ( int numofquestions = Convert.ToInt32(Console.ReadLine()) ). So it is better to declare then inside the loop (or you might accidentally use them outside or simply crowd your intellisense).Īlso, for some variables you're splitting declaration ( int numofquestions ) and assignment ( numofquestions = Convert.ToInt32(Console.ReadLine()) ), and for other you're not. But as your application gets bigger and better you don't want too many variables in scope.įrom your code: num01, num02, playeranswer, and answer are only used within the loop. This is to decrease variable pollution in bigger functions. While it might be more performance friendly to declare all variables from the outset, it is best practice, I think, to declare variables only within the scope they're used. I got some comments, some of which are my personal opinion (for example how to declare variables), some are accepted conventions (naming), and some are bug fixes. Letting the user know how many answers they got right.Ĭonsole.WriteLine("You got " + numofcorrect + " of " + numofquestions + " correct!") Playeranswer = Convert.ToInt32(Console.ReadLine()) Ĭonsole.WriteLine(playeranswer + " is correct!") Ĭonsole.WriteLine(playeranswer + " is incorrect! Try again.") Answering a question correctly increases your score.Ĭonsole.Write("What is " + num01 + " times " + num02 + "? ") This is the loop which handles the actual question/answer core of the game. Numofquestions = Convert.ToInt32(Console.ReadLine()) int timer = 30 I considered a timer function but that ended up being way over my head.Ĭonsole.Write("How many questions would you like to answer? ") It does work as intended, and I'm really just fishing for someone to yell at me for doing something glaringly bad practice in the code below. I am only a beginner when it comes to programming, but after reading tons of tutorials on and offline, I have been able to create this simple math quiz.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |