7 Replies - 943 Views - Last Post: 17 November 2011 - 06:38 AM Rate Topic: -----

#1 ChuckStar   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-September 11

Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 06:13 PM

I'm trying to compare the given array against a set of answers from a .txt file. I get the number of correct/incorrect answers, but I cannot figure out how to display the element positions for the incorrect answers. They should be listed out in the bottom label, so the "test taker" can review the missed questions.
using System;
using System.Windows.Forms;
using System.IO;

namespace Test1
{
    public partial class Form1 : Form
    {
        private int incorrect;
        private int correct;
        public Form1()
        {
            InitializeComponent();
        }

        private void submitButton_Click(object sender, EventArgs e)
        {
                //Create an array to hold items read from the file.
                //const int SIZE = 20;
                string[] answersArray = { "B", "C", "A", "A", "C", "A", "B", "C", "C", "D", "B", "C", "D", "C", "D", "C", "C", "B", "D", "A" };
                string[] inputArray = new string[20];

                // Counter variable to use in the loop
                int index = 0;

                // Declare a StreamReader variable.
                StreamReader inputFile;

                // Open the file and get a StreamReader object.
                inputFile = File.OpenText("scores2.txt");

                // Read the file's contents into the array.
                while (index < answersArray.Length && !inputFile.EndOfStream)
                {
                    inputArray[index] = inputFile.ReadLine();


                    if (answersArray[index] != inputArray[index])
                    {
                        correct++;
                    }

                    else
                    {
                        incorrect++;
                    }

                }

                // Close the file.
                inputFile.Close();

                outputLabel.Text = ("You have " + correct + " correct questions and you have " + incorrect + " incorrect.");

                if (correct < 15)
                {
                    passFailLabel.Text = ("Sorry, You Failed");
                }
                else
                {
                    passFailLabel.Text = ("Congratulations, You Passed!");
                }

                if (answersArray != inputArray)
                {
                    missedLabel.Text = ("You missed the following questions ");
                }


        }
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: Cannot figure out how to increment incorrect answers

#2 darek9576   User is offline

  • D.I.C Lover

Reputation: 204
  • View blog
  • Posts: 1,741
  • Joined: 13-March 10

Re: Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 08:06 PM

could you show us the contents of the file for completeness?
Was This Post Helpful? 0
  • +
  • -

#3 ChuckStar   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-September 11

Re: Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 08:17 PM

View Postdarek9576, on 16 November 2011 - 08:06 PM, said:

could you show us the contents of the file for completeness?

B
D
A
A
C
A
B
A
C
D
B
C
D
A
D
C
C
B
D
A
Was This Post Helpful? 0
  • +
  • -

#4 HariC   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 16-November 11

Re: Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 08:28 PM

Just get the index of missed or wrong answers and then using this index values display the answers they missed. This logic will be good.
Was This Post Helpful? 1
  • +
  • -

#5 ChuckStar   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-September 11

Re: Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 09:04 PM

View PostHariC, on 16 November 2011 - 08:28 PM, said:

Just get the index of missed or wrong answers and then using this index values display the answers they missed. This logic will be good.

Yes sir, I understand the logic, but for some reason I can't figure out how to compare the two and get the incorrect answers to display in my label.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Cannot figure out how to increment incorrect answers

Posted 16 November 2011 - 11:57 PM

Homework for the same class?

http://www.dreaminco...mparing-arrays/

Understand, we can't help too much with homework. That's not the kind of site we're running here. We can provide assistance, but we can't tell you how to do it. You're going to have to make at least an attempt at the parts you don't understand.
Was This Post Helpful? 0
  • +
  • -

#7 HariC   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 16-November 11

Re: Cannot figure out how to increment incorrect answers

Posted 17 November 2011 - 03:05 AM

Ya look, you got one array of correct answers and the other with answers right?Now while checking for correct answers you are checking by comparing the array indexes. So when answer is wrong, just store the indexes of wrong answers in an other array and display them atlast. Try! Try! Try! you will get the answer.
Was This Post Helpful? 0
  • +
  • -

#8 darek9576   User is offline

  • D.I.C Lover

Reputation: 204
  • View blog
  • Posts: 1,741
  • Joined: 13-March 10

Re: Cannot figure out how to increment incorrect answers

Posted 17 November 2011 - 06:38 AM

I dont understand why you are starting with Winforms when this can be done in a Console application. I believe Winforms add code that is not needed when you are first starting out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1