carl bloc writes:
Has any body got any code for this brief that a friend has to do, its
for the uk version of the lottery i.e 6 balls and a bouns ball.
1. a control loop is required to determine the operation required by
the user
2. use of a switch structure to execute required operation
3. read old draw data from file into arrays on programme start up
4. allow the user to enter the latest data
5. allow the user to modify existing draw data
6. view draw data for a selected week given the date of the draw or
week number
7. save the draw dta from arrays to the file on programme exit
8. the programme must validate that the ball numbers input are in the
correct range (between 1 and 49) and no duplicates.
That sounds like a very specialized program written for only one user, the
manager of the UK lottery. Also it seems to work for only one year, which
bothers me because of the "seam" problem, in other words it would have to be
a _running_ year. The suggestions below generalize the problem to work for
several years. In view of the specialized nature it seems unlikely that
anyone has such a brief lying around. I suggest your friend start by giving
some tentative data definitions. I note that you have posted a similar
question to comp.lang.c and the solution there might be quite different.
Your friend should start by enquiring of the British Government if they will
accept a solution in either language.
He might think about a data structure along these lines.
#include <time>
struct Draw
{
int ball[6]; // 1..49
int bonus; // 1..49 ??
time_t date_stamp; // probably will be a long. FYI only
};
The file would consist of several of these Draw records. As such it (the
file) would be an archive if you ignore the quibble that some person is
entitled to modify the archive according to his whim..
Modify as necessary and start writing some code, simplest thing first. If
you can't decide what is simplest toss a coin eight times. If after several
minutes you wish the coin toss had come out differently, toss the coins
again and have another go.
That is working towards a C oriented solution but using C++ syntax.
Compile often. Actually link and run frequently - but less often.
It sounds like fun, tell him to get started. (I assume it is a he)