Computer Science Canada Reading a question and the correct answer from a data file |
Author: | downisleft [ Mon Mar 09, 2009 6:01 pm ] | ||||
Post subject: | Reading a question and the correct answer from a data file | ||||
So... a little suck. my problem being i don't understand how to get both a answer and a question from a single .txt file. The problem is : Create a history drill program that: 1. Reads a history question and the correct answer from a data file; 2. Presents the question to the user; 3. Uses a subroutine to get the user's answer to the question; 4. Checks the user's answer against the correct answer and provides feedback; 5. Keeps track of the number of correct and incorrect answers; 6. Repeats steps 1 through 5 several times; 7. At the end of the quiz, informs the user of the number of correct and incorrect answers And my txt file looks like this
-- I have worked with stream before... however, each word goes into a array
(Above code used as a example how stream was used before) My question being, how (if possible) do i get turing to take the whole question? Then compare answers from the 1 txt file im using... Thanks in advance~ |
Author: | Insectoid [ Mon Mar 09, 2009 6:19 pm ] |
Post subject: | RE:Reading a question and the correct answer from a data file |
get bleh : * will get the whole line. Then just cut off the number from the start. |
Author: | downisleft [ Mon Mar 09, 2009 6:50 pm ] | ||
Post subject: | Re: Reading a question and the correct answer from a data file | ||
a start! but that still does not separate the questions which is what im having problems doing :3| So
just gets is ALL which isnt nice to play with... maybe i could get it line by line? Would be helpful T___T |
Author: | Insectoid [ Mon Mar 09, 2009 8:00 pm ] |
Post subject: | RE:Reading a question and the correct answer from a data file |
That should only get 1 line. Try replacing the comma with a colon. I swear that's the syntax (though I have been wrong in the past). |
Author: | saltpro15 [ Mon Mar 09, 2009 8:02 pm ] |
Post subject: | RE:Reading a question and the correct answer from a data file |
insectoid is right, a colon is the correct syntax |
Author: | downisleft [ Mon Mar 09, 2009 9:04 pm ] | ||
Post subject: | Re: Reading a question and the correct answer from a data file | ||
Victory is close! I can feel it ![]()
so it runs, and spits out all the info! So now i would take each line and store it into a array right? question1 answer1 question2 answer2 nsoforth Atleast... thats what i think i should do next |
Author: | downisleft [ Mon Mar 09, 2009 9:28 pm ] | ||||
Post subject: | Re: Reading a question and the correct answer from a data file | ||||
updated txt file~
And then the Program!
So im getting a few errors... and im not too sure why... ive looked over it a lot of times... maybe i shouldn't use a array? Even then... it outputs oddly Help? ![]() |
Author: | downisleft [ Tue Mar 10, 2009 1:06 pm ] | ||
Post subject: | Re: Reading a question and the correct answer from a data file | ||
It just doesn't like me i guess... only 1 error now... ERROR : 'get' width applies only to strings and char(n) I... don't understand? Google failed to help me here |
Author: | DemonWasp [ Tue Mar 10, 2009 1:34 pm ] | ||||
Post subject: | RE:Reading a question and the correct answer from a data file | ||||
You're using:
with the :* part in order to get an entire line, so that you can include spaces into the questions. However, integers can't reasonably have spaces in them. If there are numbers separated by a space: 1234 5678 , then that's two separate numbers. So, you should be using:
For future reference, CompSci.ca supports a nonstandard BBCode tag: you can add syntax highlighting by using [ syntax = "Turing" ] [ / syntax ] around your code instead of [ code ] tags (all minus the spaces, of course). |
Author: | downisleft [ Tue Mar 10, 2009 3:10 pm ] | ||
Post subject: | Re: Reading a question and the correct answer from a data file | ||
^___________________________^!!!! This is why i love programming, that sweet feeling of perfecting something!!
It works if you get them at each line... ^____^ And if the var are strings Thanks to everyone who helped Special thanks to DemonWasp, picking out the strings thing, how to get properly ![]() |