-1

I am currently working on some homework for my Visual Basics class

I have to generate two random numbers, then either add them, subtract them, divide them, or multiply them. (the user would try to guess the answer)

The only problem I am going to run into is when I want to divide.

I need the numbers to be generated, and be divisible. I am so lost of how I could do that, and google, and reading through my textbook is no help.

brendan4t
  • 1
  • 1
  • 2
    Pick a random number. Pick another temp one. Multiply them. Use the first and third (if I grok the question correctly). Not much of a guessing game - more like a math quiz. PS. it is singular: *Visual Basic* – Ňɏssa Pøngjǣrdenlarp Dec 14 '16 at 21:50
  • What do you mean by divisible? And post the code you have so far. – Tim Dec 14 '16 at 21:50
  • I assume they mean that the need a whole number as an answer so they just need to check to see if the denominator is bigger then the numerator – Sorceri Dec 14 '16 at 21:57
  • I assume "_be divisible_" you mean that you wish to cater for division by zero errors? – IronAces Dec 15 '16 at 08:29
  • OP means that the chosen numbers need to be such that the answer is an integer I think. – David Wilson Dec 15 '16 at 09:54

1 Answers1

0

This function will generate a Tuple of two numbers which when the first is divided by the second, you'll get an answer that is an integer. A Tuple is simply collection of related pieces of data, kind of like a Structure

Private Function GenerateNumbers() As Tuple(Of Integer, Integer)
    Dim rnd As New Random
    'The two lines below generate a
    Dim x As Integer = rnd.Next(99) + 1
    Dim y As Integer = rnd.Next(99) + 1
    Do Until x Mod y = 0
        x = rnd.Next(99) + 1
        y = rnd.Next(99) + 1
    Loop
    Dim result As New Tuple(Of Integer, Integer)(x, y)
    Return result
End Function

To access the numbers, use something like this in your code ..

Dim number1, number2 As Integer
Dim NewNumbers As Tuple(Of Integer, Integer)
NewNumbers = GenerateNumbers()
number1 = NewNumbers.Item1
number2 = NewNumbers.Item2
David Wilson
  • 4,369
  • 3
  • 18
  • 31