Need help with Lottery program

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 6
Reputation: Andrewsc1 is an unknown quantity at this point 
Solved Threads: 0
Andrewsc1 Andrewsc1 is offline Offline
Newbie Poster

Need help with Lottery program

 
0
  #1
Feb 17th, 2009
Im new to java and just trying to figure out the basics. i cannot figure out what is wrong with my program. Any suggestions on whats wrong?

  1. 4import java.util.Scanner;
  2. 5
  3. 6public class Lottery
  4. 7{
  5. 8 public static void main(String[] args)
  6. 9 {
  7. 10 //Generate random lottery numbers
  8. 11 int lottery = (int)(Math.random() * 1000);
  9. 12 System.out.printf("%d" , lottery);
  10. 13
  11. 14 //Create Scanner
  12. 15 Scanner input = new Scanner(System.in);
  13. 16 System.out.print("Enter your lottery pick (three digits): ");
  14. 17 int guess = input.nextInt();
  15. 18
  16. 19 //Determine whether or not the entered guess is some kind of match
  17. 20 if(guess == lottery)
  18. 21 System.out.println("Exact mactch: you win $10,000");
  19. 22 else if (guess % 100 == lottery / 100 &&
  20. 23 guess / 100 == lottery % 100 &&
  21. 24 guess % 10 == lottery / 10 &&
  22. 25 guess / 10 == lottery % 10)
  23. 26 System.out.println("Match all digits: you win $3,000");
  24. 27 else if (guess % 100 == lottery / 100 ||
  25. 28 guess % 100 == lottery % 100 ||
  26. 29 guess / 100 == lottery / 100 ||
  27. 30 guess / 100 == lottery % 100 ||
  28. 31 guess % 10 == lottery / 10 ||
  29. 32 guess % 10 == lottery % 10 ||
  30. 33 guess / 10 == lottery / 10 ||
  31. 34 guess / 10 == lottery % 10 )
  32. 35 System.out.println("Match one digit: you win $1,000");
  33. 36 else
  34. 37 System.out.println("Sorry, no match");
  35. 38 }
  36. 39}
Last edited by Andrewsc1; Feb 17th, 2009 at 6:03 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,485
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Need help with Lottery program

 
0
  #2
Feb 17th, 2009
You should probably explain what it is doing wrong, what you expect it to do, and any errors you receive, rather than expecting people here to pick through it and play "find the problem with this".
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 6
Reputation: Andrewsc1 is an unknown quantity at this point 
Solved Threads: 0
Andrewsc1 Andrewsc1 is offline Offline
Newbie Poster

Re: Need help with Lottery program

 
0
  #3
Feb 17th, 2009
sorry. well the program is supposed to tell if you won the randomly generated lottery number. i used the scanner class so that the user could enter in a number. i extracted digits from the lottery class and guess class using the "%" and "/". i cannot figure out why i cannot get the "Match all digits: you win $3,000" to appear in the console. so in all reality im just looking into why lines 22-25 are not extracting the digits.
Last edited by Andrewsc1; Feb 17th, 2009 at 6:20 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,485
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Need help with Lottery program

 
0
  #4
Feb 17th, 2009
Most likely because the formula you implemented to determine "match all digits" doesn't do that at all. Those are rather odd relationships that you are expecting between the division and mod results. You need to break the numbers into their components before you make the comparison checks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 6
Reputation: Andrewsc1 is an unknown quantity at this point 
Solved Threads: 0
Andrewsc1 Andrewsc1 is offline Offline
Newbie Poster

Re: Need help with Lottery program

 
0
  #5
Feb 17th, 2009
thank you for the help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC