|
|
So let me begin by saying I'm a little embarrassed to be posting my code considering I have no idea what I am doing |
|
|
One of the main issues I was having was figuring out how to pull the type of question then the value and store it. I'm a little lost on how to read only bits of information from a line and store it and continue to read the rest and store that. Which is what I would assume I would have to do in order to get the question type and value. |
getline(quizData, data);
, that command reads the whole line into my string variable called data
which is fine for lines that don't have multiple data (question etc.). getline
to read until it reaches that character, as an example the below code will read MC only..getline(quizData, questionType, ' ');
|
|
questionValue
an integer value of 10.
|
|
std::string qData;
etc. data is just a temporary string used so I could use stoi, once I've done that the data inside it can be overwritten.3 - How many questions TF 5 - What type of question / value of question The sun is yellow? - Question true - answer MC 10 - Type of question / value of question What is 5+5? - question 6 - how many choices Two - choice 1 (a) Three - choice 2 (b) Six - choice 3 (c) Seven - choice 4 (d) Nine - choice 5 (e) Ten - choice 6 (f) F - answer TF 5 - type of question / value of question A mouse is bigger than an elephant? - question false - answer |
|
|
Question 1: The sun is yellow? Enter Answer: true Well done, you are correct! Question 2: What is 5+5? A: Two B: Three C: Six D: Seven E: Nine F: Ten Enter Answer: F Well done, you are correct! Question 3: A mouse is bigger than an elephant? Enter Answer: false Well done, you are correct! |
Oh man, you just lifted the world off of my shoulders. haha. Here is the finished product |
First off, you shouldn't be creating an object for Question, Type, Value etc. |
std::fstream quizData;
. Everything else is only being used in the scope of CQuiz::doQuestions()
and so should be local variables.
id love you to explain based on his code how that would work then? |
or does this state "all question data must be stored in arrays".. ? |
You could reuse the data variable, there's no need to create std::string qData; etc. data is just a temporary string used so I could use stoi, once I've done that the data inside it can be overwritten. |
First line is the number of questions, then what we see is 3 common lines regardless of the question type which are Question Type, Question Value and the actual Question. You are repeating code in your IF statements - see what I mean? - Would it not be better to read those 3 lines then check the question type? |
Since this is a quiz, you need to be asking the player what the answer is and not simply listing the answer :) |
As I don't know what you've studied so far I don't know how relevant my comments are. But you do say you doing an intermediate class, which implies you should know all the basics already. And of OOA/D as well as C++ I would hope. |
I thought this would change the numQuestions value and mess up the loop. |
As strange as this sounds, the instructor did not want any user input from this code. I had to get clarity on this myself. |