Thread: C++ Simple division question - i hope

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    C++ Simple division question - i hope

    I'v just started programming in C++ and have to create a simple math game for children. The program randomly generates two numbers and a function is selected i.e + , - etc. Everything is fine except for divide as the answers have to remain whole with no decimal points.

    Has anyone got any ideas on how to generate these numbers?

    Thanx for any help,
    Jason

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    integer math leaves the answer as an int after division, as long as you are not dividing by zero. just generate two ints, and divide them.

  3. #3
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    I think he wants it so the two numbers have no remainder when you divide. You could try generating a random int, and then multiplying that by some other random int. Then your second number would be a multiple of the other. Hope that makes sense.

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Use instead Integer, float/double.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    Menu

    Thanx for the help on division question - now have that working.

    I'v run into another problem now though. I'm trying to make diffrent difficulty settings via the 'Main menu'. My hope is when you click on the diffrent difficulties like easy hard etc it will randomize up to more higher numbers.

    I know if you were using radio buttons you could put in a command like if (RadioButton1 -> Checked), then what ever you want it to do. Does anyone know what the command is for somthing under the menu bar? (I.e File > Save)

    i'v tryed if (MainButton1 -> Difficulty -> Easy -> Checked) but it doesnt reconise easy.

    Thanx for any help,
    Jason

  6. #6
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    learning110, well, what you're talking about? this sounds like you're programming in WinAPI, MFC or whatever, this don't sounds like C++ standard, If I understand you correct.

    If you're trying to ask an Windows programming specific question, ask in the correct board for that - windows programming board. Else if you're trying to make this for *nix, ask in Linux programming board.

    Don't forget to pass info there, without more info, hard to help you.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    for more difficult numbers, just do
    Code:
    rand() % hi + low
    hi, is the highest number you want generated, and low, the lowest generated...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM