Activity Stream
48,167 MEMBERS
6790 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 5 of 5
  1.     
    #1
    Member

    Default vb

    i used vb and did it all !
    cgworld Reviewed by cgworld on . c++ help i used vb and did it all ! Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    the second part generated md5...

  4.     
    #3
    Member
    Website's:
    sborg.us
    Why don't you use switch-case?

    That'll be faster, easier and good looking too!

  5.     
    #4
    Member
    Agree with V3g3t4. Switch case is preferred in these kinda cases.
    A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing. ? George Bernard Shaw
    ?
    Designer. Check my designs here.

  6.     
    #5
    Member
    Website's:
    ExpresShare.com
    well it will be good looking,easier to understand.But when compiled it will be the same as the if else statement so it's the same thing.
    Also using clases and operations will make it make the code so much cleaner and better to be understood.
    well you can solve this problem i n another way.
    let's divide this problem:
    the main 2 operations here are:
    1-choose a random number.
    2-choose a random operator.
    let's start with the first:
    1-choose a rendom number:
    We will make a function that will generate a random number for us let's call rand_number.
    the random number can be:
    a)between 0-9(if 10 questions)
    b)between 0-19(if 20 questions)
    c)between 0-29(of 30 questions)
    So there is a parameter witch is the number of the question provided by the user that will be passed to this function.
    2-choosing the random operator:
    this one is easy you can put it as a function.let's name it rand_op().a little trick will be used here so we are going to need the generated number as a parameter for this function.to put this one up we need a table that contain the operators needed (/ - + *) and the random function will choose a number between 0 to 3 (again the rand_number function will be used).
    Now the main program.
    we will repeat the process(choosing a number and choosing an operator) the needed times.in it we will be printing the operation and calculating the result.
    PHP Code: 
    #the includes here
    using namespace ..
    int rand_nuber(int n)
    {
    //returns a random integer between 0 and n}
    void rand_op(int n,int &res)
    {
    /* OP is a table contains the operators needed (/ * + -) 
    n is the generated number by rand_number will be used in the operation.
    res will store the result of the operation. */
    ope=rand_number(3);
    cout<< op[ope];
    switch 
    ope
    case 0
    res
    =res+n;
    break;
    case 
    1
    res
    =res-n;
    break;
    case 
    2
    res
    =res*n;
    break;
    case 
    3
    res
    =res/n;
    break;
    }

    void main()
    {
    //vars here.
    //get the number of questions
    maxnum_question 10;
    for (
    i=0;i<=num_question;i++)
    counter=0;
    do{
    x=rand_number(num_question-1);
    if (
    counter != max)
    rand_op(x,&res);
    }while (
    max!=counter)
    cout<< " = ??"
    //get the result from user
    //compare with the var res that u have
    //tell if he's wrong or not.
    }
    }

    NOTICE: this solution won't respect operation priority cause it's calculating while generating numbers and operations.just make sure to put a notice in your program about it or just make it respect it.think about it just a little more.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

BE SOCIAL