Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings, I am working on a project for school (so I would like advice or examples but need to do the work myself). The only way I have gotten as far as I have watching videos on youtube. Now I need some more specific help. Below is a description of the assignment, then a description of where I am at and what I am looking for. Everything is done in C#
Assignment:
The program should display the questions, one at a time, and possible answers, and accept an answer from the user. If the answer is correct, the program should go on to the next question. If it is incorrect, store the question for the second attempt and go on to the next question. When the list of questions has ended, the questions that were missed previously, or answered incorrectly, should be displayed again, in their original order. Keep a count of the correct answers for each category of questions and display the final count after two attempts. Also, display the correct answer, when necessary, in the second round of questioning.

What I have tried:

The first time I have ever done this form of programming is 3 weeks ago so I am VERY new (have experience programming CNC machines but that is entirely different). I have managed to get the questions all in and when they are answered by the user it can register if it is correct or incorrect. I am trying to figure out how to get it to loop around a second time (after all the questions have been asked) to ask only the questions that were answered incorrectly, then at the end of the second loop (if necessary) give the number correct out of the total. I tried having Correct = 1 then at the end of the program put a line in for it to add "Correct" up but it only seems to register 1 and not the 10 times it should.
Any help would be greatly appreciated.
Posted
Updated 10-Nov-17 1:27am
v2
Comments
Suvendu Shekhar Giri 10-Nov-17 0:07am    
Please share the relevant code block/problematic piece.
Member 13513329 10-Nov-17 3:14am    
Version 4 code with all questions and answers replaced with generic info.

public static void Questionone()
{
Console.Write("Q1) Pick wrong?\n1) Right\n2) Other\n3) Wrong\n4) Dont pick\n");
int answer1 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message1 = (answer1 != 3) ? "Incorrect" : "Correct";
Console.WriteLine(message1);
}
public static void Questiontwo()
{
Console.Write("Q2) Do you know?\n1) True\n2) False\n");
int answer2 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message2 = (answer2 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message2);
}
public static void Questionthree()
{
Console.Write("Q3) Pick me?\n1) Me\n2) You\n3) Them\n4) They\n");
int answer3 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message3 = (answer3 != 1) ? "Incorrect" : "Correct";
Console.WriteLine(message3);
}
public static void Questionfour()
{
Console.Write("Q4) Which is up?\n1) Left\n2) Up\n3) Down\n4) Right\n");
int answer4 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message4 = (answer4 != 3) ? "Incorrect" : "Correct";
Console.WriteLine(message4);
}
public static void Questionfive()
{
Console.Write("Q5) Pick one?\n1) Top, Middle, and Lower\n2) Yes, no, otherwise\n3) Maybe, Probably not, Definately not\n4) Front, back, side\n");
int answer5 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message5 = (answer5 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message5);
}
public static void Questionsix()
{
Console.Write("Q6) Guess.\n1) True\n2) False\n");
int answer6 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message6 = (answer6 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message6);
}
public static void Questionseven()
{
Console.Write("Q7) You bet.\n1) True\n2) False\n");
int answer7 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message7 = (answer7 != 1) ? "Incorrect" : "Correct";
Console.WriteLine(message7);
}
public static void Questioneight()
{
Console.Write("Q8) Up.\n1) True\n2) False\n");
int answer8 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message8 = (answer8 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message8);
}
public static void Questionnine()
{
Console.Write("Q9) Cool.\n1) True\n2) False\n");
int answer9 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message9 = (answer9 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message9);
}
public static void Questionten()
{
Console.Write("Q10) X has happened ____ time(s) before.\n1) Zero\n2) One\n3) Two\n4) Three\n");
int answer10 = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
String message10 = (answer10 != 2) ? "Incorrect" : "Correct";
Console.WriteLine(message10);
}
public static void Main(string[] args)
{
Console.Write("Name: Me\nCourse: my course\nAssignment title: My Quiz\nTo answer enter the number of your choice then press enter, then any button.\n");
Questionone();
Questiontwo();
Questionthree();
Questionfour();
Questionfive();
Questionsix();
Member 13513329 10-Nov-17 3:19am    
Here is the last little bit that is not on there...

Questionseven();
Questioneight();
Questionnine();
Questionten();
Console.ReadKey();

Here's a general guidance: on the first pass of questions, add to a list of questions those which have not been answered correctly. After the first pass, iterate over this questions list and ask them a second time.
 
Share this answer
 
Comments
Member 13513329 10-Nov-17 3:42am    
That is kind of what I was thinking I would have to do but that could get really layered (at least with how I am imagining it in my mind, maybe there is a better way?). This is what I am thinking (with just 2 questions):

Q1
right go to Q2
wrong go to Q2.2
Q2
right 2/2 correct
wrong go to Q2.1
Q2.1
right 2/2 correct
wrong 1/2 correct
Q2.2
right go to Q1.1
wrong go to Q1.2
Q1.1
right 2/2 correct
wrong 1/2 correct
Q1.2
right 1/2 correct
wrong go to Q2.3
Q2.3
right 1/2 correct
wrong 0/2 correct
phil.o 10-Nov-17 3:53am    
This is not a good solution as it will give you an exponential number of cases.
Why not taking the OOP way, creating a class Question with all relevant fields (question text, choices and right answer), then create a list of questions over which you will be able to iterate? During the iteration, you can increase the counter if right answer is provided, or add the question to the "second chance" list if answer was incorrect. Then iterate over the second chance list if needed.
Member 13513329 10-Nov-17 4:44am    
How would I do that? Can you give an example or link to one? I do not know how to do a counter or get the second chance. I posted in what I have for code so far above so you can see where I am at.
Answering to your comment:
A counter is just an int variable that you can increase.
Here are a few links, you should take time to get a basic understanding of OOP programming:
Classes (C# Programming Guide)
C# Lists examples
Create a Multiple Choice Quiz with arrays in C#
These are only some general guidances to show you how you can structure your program in an OOP way; they are not a direct solution that you can copy/paste.
You should first study a little bit of classes and lists, then take a pen and paper and write down the process using your newly acquired knowledge. It is quite hard to give you meaningful guidance since we do not know how much of c# development you already know; the only thing that can be said is that the way you first considered to architect your program will come and bite you very quickly.
Finally, here is some kind of general algorithm to help you started:
C#
int counter = 0;
List<Question> questions = new List<Question>();
// Fill this list with questions
List<Question> wrongAnswered = new List<Question>();
for each (Question question in questions) {
  // Present the question to the user and wait for the answer
  // If answer is correct -> increment counter by 1
  // If answer is incorrect, add the question to the wrongAnswered list
}
for each (Question question in wrongAnswered) {
  // Present the question to the user and wait for the answer
  // If answer is correct -> increment counter by 1
}
// Present the result (counter) to the user

Hope this helps. Kindly.
 
Share this answer
 
Comments
Member 13513329 10-Nov-17 6:04am    
Thanks for the help, I will learn about that area and what to do.
Without doing the work for you, I'll give you some approaches I would use. I'm assuming you're NOT connected to a database.


    I would create a data structure
  • It would contain the question
  • It would contain whatever you want to server as the answer
  • It would contain a field to mark question correct
  • It might also contain fields for counting the number of tries, etc., depending upon what else you'd like to do.


An array of these structures can be gone through and handled any way you wish.

Learning to understand, create and use data structures will server you very well !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900