[nfbcs] Trivia game help

Jim Barbour jbar at barcore.com
Tue Apr 18 17:18:19 UTC 2017


How are you separating out the questions and the answers?

Jim

Can I suggest some code like the following to see if the basic pieces are working?

        static void Main(string[] args)
        {
            Console.WriteLine("Enter your answer");
            string AnswerEntered;
            AnswerEntered = Console.ReadLine();
            if(AnswerEntered=="CorrectAnswer")
            {
                Console.WriteLine("You are correct!");
            }
	    else
	    {
                Console.WriteLine("\"{0}\" does not equal \"CorrectAnswer\"",AnswerEntered);
            }
        }

I don't have a c# interpreter, so I haven't tested this code.  But,
I'm pretty sure it comes close to testing what you want :)

Good Luck!

Jim

On Tue, Apr 18, 2017 at 12:55:05PM -0400, Taylor Arndt via nfbcs wrote:
> What is in my file is a whole bunch of questions, and i just wanted to
> make sure it sort-of worked before i put the rest of the questions in.
> I have about 30 questions in this file, each having 4 choices each.
> 
> On 4/18/17, Jim Barbour via nfbcs <nfbcs at nfbnet.org> wrote:
> > I agree with everything Tyler said.  I was in the middle of writing
> > something similar when I saw his email.
> >
> > The other thing I'll point out is that your if statement is...
> >
> >          if(AnswerEntered=="CorrectAnswer")
> >
> > So, it's checking your input against the literal string "CorrectAnswer",
> > which I assume is not what you want.
> >
> > Hope this helps,
> >
> > Jim
> >
> > On Tue, Apr 18, 2017 at 12:24:28PM -0400, Littlefield, Tyler via nfbcs
> > wrote:
> >> Taylor:
> >> This is one of those code files that I look at and don't really know
> >> what to do with. I'm going to give you a lot of information here.
> >> First, don't store everything in objects. Objects are quite literally
> >> what everything inherits and you're going to run into a lot of issues.
> >> If something is a string, make it a string. If it's an array, make it an
> >> array.
> >> Second, you need to evaluate why there are so many variables, whether or
> >> not you need them and most importantly why they're all private static. I
> >> recommend creating a separate game object that your main method can load
> >> and work with.
> >> third, evaluate your logic.
> >> Right now you request an answer from the user (without showing the
> >> question), read a list of questions, create another question and want an
> >> answer to that from what I can tell.
> >>
> >> So your logic should look like this:
> >> 1) read a list of questions and answers and store those somewhere. It
> >> might be worth creating a Question class that holds the question and
> >> individual answers. Then just store a list of those on your main class,
> >> in your main method or in a game class. The latter is preferable.
> >> 2) Randomly choose a question from the list, store that question so you
> >> have a reference to it and print the question itself.
> >> 3) prompt user for answer
> >> 4) compare answer with that of the question.
> >> HTH,
> >>
> >>
> >> On 4/18/2017 12:03 PM, Taylor Arndt via nfbcs wrote:
> >> > Hi, so i am making a trivia game in c#. I have a sample question in an
> >> > array, but i can't seem to get so that it will check if it is correct.
> >> > It keeps reading the text file and won't check if answer is correct.
> >> > Here is my code
> >> >  using System;
> >> > using System.Collections.Generic;
> >> > using System.Linq;
> >> > using System.Text;
> >> > using System.Threading.Tasks;
> >> > using System.IO;
> >> >
> >> >
> >> >
> >> >
> >> > namespace Trivia_Game
> >> > {
> >> >     class Program
> >> >     {
> >> >         private object questionArray;
> >> >         private object stringquestion;
> >> >         private object stringcorrectAnswer;
> >> >         private object question;
> >> >         private object userAnswer;
> >> >         private int credit;
> >> >         private static int score;
> >> >         private static object correctAnswer;
> >> >         private static string stringuserAnswer;
> >> >         private static bool user;
> >> >         private static int i;
> >> >         private static string dataFile;
> >> >         private static string[] shuffledLines;
> >> >         private static object file;
> >> >         private static string Key;
> >> >         private static object reader;
> >> >         private static object Reader;
> >> >         private static object streamReader;
> >> >         private static FileStream fileStream;
> >> >         private static object questionIndex;
> >> >
> >> >         public static object QuestionArray { get; private set; }
> >> >
> >> >         static void Main(string[] args)
> >> >         {
> >> >             Console.WriteLine("Enter your answer");
> >> >
> >> >
> >> >             string[] lines = File.ReadAllLines("questions.txt",
> >> > Encoding.UTF8);
> >> >
> >> >             string AnswerEntered;
> >> >             AnswerEntered = Console.ReadLine();
> >> >
> >> >             foreach (string line in lines)
> >> >             {
> >> >                 string[] questions = new string[1] { "What was the
> >> > version number of ios that introduced voiceover?" };
> >> >                 string[] CorrectAnswer = new string[1] { "A"};
> >> >                 Console.WriteLine(line);
> >> >                 Console.WriteLine("Enter an answer");
> >> >
> >> >                 AnswerEntered= Console.ReadLine();
> >> >
> >> >                 string[] IncorrectAnswer=new string [1] {"B"};
> >> >
> >> >                 if(AnswerEntered=="CorrectAnswer")
> >> >
> >> >                 {
> >> >                     Console.WriteLine("You are correct!");
> >> >                 }
> >> >
> >> >                 Console.ReadLine();
> >> >
> >> >             }
> >> >         }
> >> >
> >> >
> >> >
> >> >     }
> >> >
> >> > }
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >> --
> >>
> >> Take Care,
> >> Tyler Littlefield
> >>
> >> Me on the web <http://tysdomain.com> @Sorressean on Twitter
> >> <http://twitter.com/sorressean>
> >> _______________________________________________
> >> nfbcs mailing list
> >> nfbcs at nfbnet.org
> >> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> >> To unsubscribe, change your list options or get your account info for
> >> nfbcs:
> >> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/jbar%40barcore.com
> >>
> >
> > _______________________________________________
> > nfbcs mailing list
> > nfbcs at nfbnet.org
> > http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> > To unsubscribe, change your list options or get your account info for
> > nfbcs:
> > http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/taylorarndt99%40gmail.com
> >
> 
> 
> -- 
> Taylor
> 
> _______________________________________________
> nfbcs mailing list
> nfbcs at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> To unsubscribe, change your list options or get your account info for nfbcs:
> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/jbar%40barcore.com
> 




More information about the NFBCS mailing list