Author Topic: Programming  (Read 1634 times)

leroy_jenkins22

  • Guest
Programming
« on: May 16, 2013, 03:59:46 am »
I am doing a kids maths game and when they click on the right answer i want a new question and answers to appear in a random order, how do i do that?

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Programming
« Reply #1 on: May 16, 2013, 08:23:48 am »
a rather broad question.. what exactly do you struggle with?

m4unot

  • Guest
Re: Programming
« Reply #2 on: May 16, 2013, 03:10:52 pm »
Look at: http://dragonfiresdk.net/forum/index.php?PHPSESSID=b7s8dba2cu3a2v1c6kpilshng6&topic=591.msg3140#msg3140

in case you want i can make the whole thing to you for a small payment.

leroy_jenkins22

  • Guest
Re: Programming
« Reply #3 on: May 17, 2013, 02:04:11 am »
I just want to know how to make another question and answer pop up randomly when they click on the correct answer (as simple as possible please since i just started)
« Last Edit: May 17, 2013, 02:40:45 am by leroy_jenkins22 »

m4unot

  • Guest
Re: Programming
« Reply #4 on: May 17, 2013, 05:33:55 am »
I can see you are having hard time to understand how. let me show you something top of my head that does waht you want:

Code: [Select]

#include <iostream>     // std::cout
#include <algorithm>    // std::random_shuffle
#include <vector>       // std::vector
#include <ctime>        // std::time
#include <cstdlib>      // std::rand, std::srand



 int input = 0;

 // our numbers

 int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};



 // our answers based on right or wrong

 char * right_answer [] = { "Perfect!", "Excellent!", "You are good!", "Wow!"

};


 char *  wrong_answer[] = { "Wrong!", "Not good enough!", "Try again!", "Loser!"

};



unsigned dataArraySize = sizeof(a) / sizeof(int);

std::vector<int> v(a, a+dataArraySize);

std::vector<std::string> right_answers(std::begin(right_answer), std::end(right_answer));

std::vector<std::string> wrong_answers(std::begin(wrong_answer), std::end(wrong_answer));



// random generator function:

int random_generator (int i) {
 
  return std::rand()%i;

}

void seed(void){
 
  std::srand ( unsigned ( std::time(0) ) );
 
 }




void Update_our_math(void){

 
   // Random math question

  std::random_shuffle(v.begin(), v.end());

 
  // making it more random

  std::random_shuffle ( v.begin(), v.end(), random_generator);



  // Random right/wrong answers

  std::random_shuffle ( right_answers.begin(),  right_answers.end() );

  std::random_shuffle ( right_answers.begin(),  right_answers.end(), random_generator);


  std::random_shuffle ( wrong_answers.begin(),  wrong_answers.end() );

  std::random_shuffle ( wrong_answers.begin(),  wrong_answers.end(), random_generator);


 
 }



int main(){

  //Most be used one time only

  seed();


  // call this everytime you need new question and answers

  Update_our_math();
 
  // Use it...


  std::cout <<v.at(0)<<" + " << v.at(9) << " ?" << std::endl << std::endl;


  std::cin >> input;


  if(input == (v.at(0) + v.at(9)) ){


    std::cout << std::endl <<right_answers[0].c_str() << std::endl<< std::endl;


   } else{
   
        std::cout << std::endl << wrong_answers[0].c_str() << std::endl << std::endl;

  }


  system("pause");


 
  return 0;


}



Try to compile my code into a empty project and learn from it. You can use it inside dragonfiresdk without any problem :)
« Last Edit: May 17, 2013, 06:46:39 am by m4unot »