[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Help a newby to programming out
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 9
Thread images: 1
File: girl-with-headphones.jpg (863 KB, 3840x2160) Image search: [Google]
girl-with-headphones.jpg
863 KB, 3840x2160
Hello /g/. I want to write a program in C that pulls questions from a list as well as answers for a trivia game. The program would display a random question from a list of questions I premade. Then ask the user for an answer. I would take the input from the user and compare it to the corresponding answer from the list. The thing is I don't know how I would go about doing this. Can I make the list of questions in notepad and pull it from there? Can i create a spreadsheet for the questions and answers in a database and pull the questions randomly from there? How would I go about making this program? Any help and answers will be greatly appreciated.
>>
>>53648410
put it in a .html file and then parse it
>>
>>53648410
How newby is newby? From your range of questions I would imagine brand new, and if that's the case you're starting with a project that might be a bit out of your league.

It's not that the task at hand is hard, it's just the fact that you don't know simple things like reading from files or, perhaps, populating arrays and randomly selecting from them. Try some elementary programming challenges for C that focus on your particular needs, piece by piece, and then go for there
>>
>>53648518
>go for there

Go from there.*
>>
>>53648480
>>53648518
Yes completely new. Thanks a lot.
>>
>>53648410
You could create a library of question objects. The object would be something like string question string answer.

You use some kind of random function to make the array random and then pull each question one at a time.

If you want the question to be multi choice. You give the question objects 3 fake answers.

If you make it multi choice you won't have to handle misspelling and complex answers. Just a b c or d
>>
>>53648480
I think html might be a bit much to ask for parsing for a newby. I think using a csv would be better and wouldn't require some external C-html lib.

<question>, <answer>
What is the powerhouse of the cell?, mitochondria
Is OP always gay?, yes
>>
>>53648410
You can write your QA in a spreadsheet and export it as a CSV file.
>>
>>53650553
>>53652473
Screw this. Put in in a record jar.
Planet: Mercury
Orbital-Radius: 57,910,000 km
Diameter: 4,880 km
Mass: 3.30e23 kg
%%
Planet: Venus
Orbital-Radius: 108,200,000 km
Diameter: 12,103.6 km
Mass: 4.869e24 kg
%%


OP, make sure you keep your parsing logic completely separate from everything else. This is a really good case-study for Unix software engineering skills.
Thread replies: 9
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.