Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic maths game help, division.

    Hi all,

    Just recently started programming so apologies if this is noobish.

    I am making a basic maths game for a project and are just having a few problems with it. I have four questions, multiply, add, division and minus and all the numbers are randomly generated. However I am trying to get my head round how I could make the division numbers only even, or numbers that won't leave decimals remaining in the answer, 10 divided by 7 = 1.428 etc.

    This is my code for the division problem. Divide one and divide 2 are the two separate numbers that will appear to be divided. I've made it so the first number is always larger than the first one, but now are trying to avoid these awkward numbers that cause remainders.


    // Fill in the division problem.
    divide1 = randomizer.Next(5, 11);
    divide2 = randomizer.Next(2, 4);
    DivLLabel.Text = divide1.ToString();
    DivRLabel.Text = divide2.ToString();
    sum3.Value = 0;


    Thanks in advance.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Simplest solution:

    Generate two random numbers.

    The first number for the divide will be the two random numbers multiplied together, the second number for the divide will be one of the random numbers - so the answer will be the other random number.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great thanks! Appreciate it.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •