Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: need help sa C

  1. #1

    Default need help sa C


    kanang mangayu unta kog tabang ani:

    -unsaon pag generate ug random questions if for example naa kay game nga program like who wants to be a millonaire or unsa.
    -dayun asa man kuha ang function nga mu randomize sa mga questions nga dapat i randomize?


  2. #2

    Default Re: need help sa C

    murag naa man rand() or randomize() nga function bro. kaw lng set sa limit. basta dali ra kaayo na bro.

  3. #3

    Default Re: need help sa C

    ahhh..nakadungog sad ko ana bro pero ang ako bro bah, unsaon man pag randomize sa angay i randomize

    ako idea ana kay silbi naay koy usa ka library sa mga questions then mao i call sa randomize..
    mao ako idea,pero mangayu unta kog example bah.

  4. #4

    Default Re: need help sa C

    Quote Originally Posted by chokobo
    ahhh..nakadungog sad ko ana bro pero ang ako bro bah, unsaon man pag randomize sa angay i randomize

    ako idea ana kay silbi naay koy usa ka library sa mga questions then mao i call sa randomize..
    mao ako idea,pero mangayu unta kog example bah.
    Butangi lag ID ang kada question sa imo Library baii...
    Then kanang ID which is an int integer maoy imo i pass sa randomize nga function....

    Then imo i pair ang ID sa kada question....
    Just an idea lang ni ako...

  5. #5

    Default Re: need help sa C

    sayon ra na bro, example you have 5 questions. di nako kahinumdum sa exact nga pag gamit pero sabta nlng...
    mag randomize kag 5 integers. so you can generate integers 1 - 5 in random. then imu questions ibutang nlng nimu ug switch or if statements. from there, mkagenerate na kag ramdom questions.

  6. #6

    Default Re: need help sa C

    gae daw kog concrete example bai, bisan mga 3 questions lang or bisan murag scratch

  7. #7

    Default Re: need help sa C

    you can also replace your switch statements with tables instead (implemented as an array of structures)

  8. #8

    Default Re: need help sa C

    #include <stdio.h>
    #include <sys/types.h>
    #include <time.h>

    void seed_random();
    int get_random(int);

    main()
    {
    Â* seed_random(); /* note:dont seed the random function everytime you call it */
    Â* int random_no = get_random(100);

    Â* printf("%d ", random_no);

    Â* return 0;
    }

    void seed_random()
    {
    Â* time_t t1;
    Â* (void) time(&t1);Â*
    Â* srand((long) t1); /* use time to set seed */Â*
    }

    int get_random(int limit)
    {
    Â* return rand() % limit;
    }


    here's a code to generate random numbers using the system time as seed.
    as what almost everyone here said, assign an integer id to each of your question. that would be from 0 to the number of your questions minus 1.
    you can put your questions with the ids in a database or in a file or anywhere you want for persistence as long as you have the means to query a particular question using its designated id.
    use the get_random to get a random number and then use the random number to query the question. dont forget to pass the total number of questions as the argument for the get_random function.

    note: seed the random function only once. typically, during startup of the application. unless kailangan jud nimo magsige ug seed, which i really dont think you do.

    good luck bay! kaya ra na nimo uy! :mrgreen:

  9. #9

    Default Re: need help sa C

    ah thanks bai pero la pako knowledge sa seed

    ako nlng ghimuan ug lain paagi
    wa nlng nako gi random

    thanks ninyo!

  10. #10

    Default Re: need help sa C

    ahh ok.. cge bay good luck! :mrgreen:

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. need help sa linux be version 9
    By kermesh in forum Computer Hardware
    Replies: 3
    Last Post: 03-01-2013, 03:10 PM
  2. Guys need help sa business na carwash
    By mack0y in forum Business, Finance & Economics Discussions
    Replies: 7
    Last Post: 01-29-2013, 12:41 AM
  3. internet cafe business, need help sa specs?
    By jaytol23 in forum Networking & Internet
    Replies: 19
    Last Post: 04-22-2012, 12:38 AM
  4. guys i need help sa mga famous in guitars & effects
    By casterTroy in forum Music & Radio
    Replies: 37
    Last Post: 08-27-2007, 06:43 PM
  5. need help...sa akong mobo sound card
    By Fern in forum Computer Hardware
    Replies: 18
    Last Post: 06-19-2007, 04:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top