❔ Urgent help - Multiple Choice Quiz Project with Csv File - Windows form C#
I have two forms, Menu form, and Quiz Form.
What to Know:
- user can select 1 of 2 topics : Cell Biology or Organisation
- Questions are passed through via Csv file - Excel
- Im not sure how i can filter the questions displayed based on the users topic selected.
- i created a ID for each question so for if topic A selected questions 1-15 displayed, if Topic B selected 16 - 30
- I need 10 questions picked at random and displayed from the 15 questions for each topic
- the total score is displaying weird out of 30 after only 10 questions answered.
Issues:
- Questions not filtered based on user selected topic - MAIN PROBLEM
- Right Answers tracker not working properly
- score board not working
please guys im in desperate need of help
ive provided screenshots and source code
https://paste.mod.gg/ditwjlzstnfa/0
BlazeBin - ditwjlzstnfa
A tool for sharing your source code with the world!
33 Replies
Let's start with "the total score is displaying weird out of 30 after only 10 questions answered."
What do you expect this line of code to do?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Ive fixed that now to:
MessageBox.Show($"Your score: {rightAnswers} out of 10");
Hard coding '10' rather than dynamically computing how many questions were actually asked seems like going in the wrong direction.
im aware 30 questions were loaded in
and that was counted
That doesn't change the fact that hard-coding the string '10' is not the right way to do this kind of thing.
understood, do you know how i can only read in only questions that have the topic the user selected from the menu form
What have you tried?
I was thinking I could do an if statement , if selected topic from the combo box equals oneQuestion.Topic then read it it in
But I’m not sure how to do it
Here, I put in a comment. You just need to replace the comment with some code.
I was able to display whatever they selected to the Label
Did you write most of this program yourself? Or did you copy / paste a lot of the code from somewhere?
I wrote majority myself, then use helped from chatgpt
Because if you aren't sure how to use an
if
statement to make sure the topic matches it feels like you are missing some fundamentals.Ik how is statemetnts work but it’s just I don’t know how I would write it , using the topic slected from the user from the Menu Form to the Quiz Form @
If u know what I mean
Honestly I appreciate you helping
You already have a field called
selectedTopic
is there a reason you can't just compare against that?It gives syntax error
Show the code you wrote and what the error says
Apologies I’m AFK, using my phone rn
I’ll be home in 20 mins
theres a problem
when I run the program and choose "Organisation" , it works
heres what csv file looks like for reference
when I run the program and choose "Cell-Biology" , error
That error message is telling you that the file is already opened for exclusive access by something else (possibly your code)
When you open a file you should use a
using
scope to ensure it always get disposed deterministically.
Something like that
Also you probably should just read the file in once when your program starts - put the contents into a List or a Dictionary and then pick the questions from that rather than re-reading the file every time.this happens when its run , when i choose the "cell-bioloyg topic"
right
it doesnt seem to read in "Cell-Biology":
I had the csv file open
.
Apologies
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.