![]() |
|
[C] Outputting random question set? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Outputting random question set? (/showthread.php?tid=5162458) |
Outputting random question set? - Aus10 - Feb 7, 2016 So here is the backstory in order to understand this issue! I am using one function to read in questions and answer choices from a .txt file. However, instead of just using the read in function to cout the text in the file... I want to use a different function to cout a random question from the file. How would I go about doing this? My goal here is to randomly read in a question and its set of answer choices, one at a time, while including the A. B. C. D. in front of each answer choice. ( ABCD is not in the .txt file ). Here is my code thus far ... PHP Code Thanks! * - Annabelle Lee - Feb 7, 2016 (Feb 7, 2016 03:20 PM)Aus10 Wrote: I am using one function to read in questions and answer choices from a .txt file. This is why you pass arguments to functions. Take in the file, pick a random number/line that you want to keep it. Pass it as an argument to a function to output it using cout. That's about it. * - Aus10 - Feb 7, 2016 I sort of understand, and tried it. However when you say take in the file, where should I do this? It seems I'm trying to pass a function as an argument into another function. A function into a function, I've been researching and can't seem to find examples. :/ * - Annabelle Lee - Feb 7, 2016 Basically you'll make two functions. Pseudocode follows. No need to pass a function to a function. Reading Function Get/open file Read it in, stop at random line. Save that line to a string/etc as you need. Call Output_function(string you got of that line) Close file End function Output_function Take the string it got from argument cout << string << endl; // other stuff you have to output, options, etc. * - Aus10 - Feb 7, 2016 That clears alot up. Thank you very much for your help! |