![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 1
Rep Power: 0
![]() |
programming problem
I am a student in a java programming class. We have to write a program as described below. The teacher is not giving us any help. I don't have a whole lot of programming experience and am not sure what to do. Can anyone explain what the code should look like?
Thanks in advance for any help. ----------------------------------------------------------------------- Write a program to create an Instant Lottery. It cost one dollar to play. A player enters 6 numbers between 1 and 40. After the last number is entered, the computer generates a 6 number winning ticket and compares the player’s numbers to the winning numbers. Payout is according to the following table: Number matched Printed Result 0 Sorry, Better luck next time. 1 Congratulations, you won $1. 2 Congratulations, you won $5. 3 Congratulations, you won $100. 4 Congratulations, you won $1000. 5 Congratulations, you won $10000. 6 Jackpot!!! You won $1 million. Run the game 10 or more times. For each play, print out the player’s numbers, the computer’s numbers, and the results from the table above. At the end, report the total number of games played, the amount wagered, the amount won, and the net gain (won – wagered). |
|
|
|
|
#2 | |
|
Programmer
|
Quote:
We arent going to do your homework for you, sorry. Post the code that you have now. If you have none, start by making a simple program to input numbers between 1 and 40 from a user and printing them out. You probably want to use arrays to store the input numbers, and the generated numbers. JD |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Read your book, mate. A lot of times the instructors will take examples right from the textbook and tweak them, but it's essentially the same program as what has already been written.
|
|
|
|
|
#4 | |
|
Programmer
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4
![]() |
Quote:
__________________
#if 0 /* in case someone actually tries to compile this */ <Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode? |
|
|
|
|
|
#5 |
|
Programmer
|
wow its a joke, hence no code tags
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
fuck syntax. c++, c, delphi, java, python, or d. get a pen and paper and think about the problem. draw pictures, make flowcharts. work out situations in your head. this is a pretty simple example but the hardest thing to do in programming is using abstract thought to analyze the problem. it gets easier with time. take lots of math. it takes a lot of abstraction to move from an apple falling from a tree to calculating instantaneous velocity and later on, the theory of gravity. the more you do stuff like this, you'll start to see the world in a different way, like in "interview with the vampire" when brad pitt first saw the world with his "vampire eyes", it's amazing what the world turns into when you look at it with your "CS/math eyes".
edit...how much money do you start with? it costs $1 to play, but a computer will let you play with negative money. don't let this happen, unless of course you want to extend credit to a player and then give them a virus or something if they don't pay up. :p
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
#7 |
|
Newbie
Join Date: Apr 2005
Location: NC,USA
Posts: 17
Rep Power: 0
![]() |
public class Lottery
{
public static void main(String[] args)
{
int[] a= {0,0,0,0,0,0};
while(a[5]==0)
{
int n=(int)Math.ceil(Math.random()*49);
if(a[0]==0) a[0]=n;
else
if(a[1]==0 && n!=a[0]) a[1]=n;
else
if(a[2]==0 && n!=a[0] && n!=a[1]) a[2]=n;
else
if(a[3]==0 && n!=a[0] && n!=a[1] && n!=a[2]) a[3]=n;
else
if(a[4]==0 && n!=a[0] && n!=a[1] && n!=a[2] && n!=a[3]) a[4]=n;
else
if(a[5]==0 && n!=a[0] && n!=a[1] && n!=a[2] && n!=a[3] && n!=a[5])
a[5]=n;
}
System.out.print("LUCKY NUMBERS: ");
for(int i=0; i<6; i++)
{
System.out.print(a[i]+" ");
}
}
} |
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|