Link to home
Start Free TrialLog in
Avatar of MasterOfTheSky
MasterOfTheSky

asked on

Excel VBA Question (Please utilize For Loop & Do Loop)

There is a selection of five random digits that the “winning number.”  The user should be able to buy as many tickets (each containing five random numbers) as they would like at $1 per ticket.   If one of the user ticket matches the winning number, the user wins $100,000.  Assuming that  order matters, if the winning number is 21345, then 12345 doesn’t win.)

I am trying to write a sub that will first, generates a random winning number, then stores it in a string variable so that you can use string concatenation,  next it will asks the how many cards user wants to buy. It must then use a For Loop to generate this many cards and store their number in a card array which should be a string array.  Next, it should use a DO LOOP to keep checking cards until a winner has been found or no more cards remain.  Lastly,  it must display a message saying whether you are a winner and what your net gain or loss.  A single random digit from 0 to 9 can be generate with excel’s RandBetween Function.
ASKER CERTIFIED SOLUTION
Avatar of kittenwhisky
kittenwhisky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Patrick Matthews
MasterOfTheSky,

With respect, this question appears to be an academic assignment.  Putting that aside for the moment...
  • Why is it so important that you use a For...Next loop to generate the cards?  That is certainly one way to do it, but hardly the only way
  • Again, why is it so important to use Do...Loop t check the cards for the winner?  Again, while that is one way to do it, there are other, equally valid ways
  • You have not specified whether this is really a raffle, or a lottery.  The difference is important: in a raffle, a winning ticket has always been sold, but in a lottery, (a) there not be a winning ticket sold and (b) more than one ticket with the winning number(s) may have been sold
Please clarify whether this question is related to an academic assignment.

Patrick
Avatar of MasterOfTheSky
MasterOfTheSky

ASKER

Matthewspatrick my co workers and I are conducting an experiment on lottery tickets.  Thank you!!
Thank You very much!! It works!!!