Hey everyone, I just need a little help with a lottery program I have to make or class. I have to generate a 7 digit number and then using that number compare it to a guess the user enters. I need to award prizes for the following conditions.
if all numbers match $1000
if all even place numbers match $500
if all odd place numbers match $250
First and last digits match $100
Im using math.Random() to generate the number im just having issues getting the specific place values and comparing them to the answer, for example if the user enters the number 4875297 and the lottery generates 7845397. Since all the even place numbers match (8, 5, 9) the user would win $500, but how do I select the specific place value to compare
I wasnt asking you to do my homework thanks, I only asked 1 question regarding a specific aspect of it. I didnt post my homework in full and say figure it out. All I wanted to know was how to select place values of a seven digit number. Infact I tried to be as clear as I could to avoid anyone thinking that I was trying to get someone to do it for me. All I need is a push in the right direction.
Sorry about that i read most of your post saw what appeared to be an asignment with no code and assumed you were, "asking us to do your homework."
I apoligize for my horrible mistake.
Now that i have read your full post as well as the others:
have you covered modulus, %, in your class? if so we can make use of it to make a simple method to get any digit of a larger number.
ill give you some examples then see if you can work out a method to do what you want.
if we want to get the 100s place of x = 4536728; we can do (x/(10^2)) % 10 which equals 7.
So shift the hundreds place to the ones place by deviding by 100 and find the remainder of deviding by ten using modulus. This gives us the value of the ones place (the number that was in the hundreds place)