[nfbcs] Trivia game help

Drenth, Joe Joe.Drenth at JBTC.COM
Tue Apr 18 16:26:19 UTC 2017


Hello Taylor,

What is in your question input text file? 
You are looping through each line of the input file, each time asking the same question about when VoiceOver was introduced and then writing one line from the input file, which seems a little unusual.

You are also testing the text the user entered against the string "CorrectAnswer", rather than comparing it to the contents of the string variable named CorrectAnswer.

Another point is that you should always use String.Compare to test two strings, since testing for equality of string objects will only check if the references are to the same block of memory.


Joseph Drenth 
R&D Software Engineer 
JBT Corporation  |  Automated Systems 
400 Highpoint Drive 
Chalfont, PA  18914, USA
E: joe.drenth at jbtc.com  P: 215 822 4457
www.jbtc-agv.com 

-----Original Message-----
From: nfbcs [mailto:nfbcs-bounces at nfbnet.org] On Behalf Of Taylor Arndt via nfbcs
Sent: Tuesday, April 18, 2017 12:04 PM
To: NFB in Computer Science Mailing List
Cc: Taylor Arndt
Subject: [nfbcs] Trivia game help

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();

            }
        }



    }

}





--
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/joe.drenth%40jbtc.com




More information about the NFBCS mailing list