[an error occurred while processing this directive]
/*
========================================================
COMPILATION SUCCESSFUL
Submitted on: 20011129 at: 13:00:02 from: 10.0.0.26
========================================================
*/
/* Niall O'Brien 20011116
This program will generate random lotto numbers (number of sets based upon user input).
*/
// Include header files
#include
#include
#include
main(void)
{
// Declare all variables required for program
int randomcounter, setcounter, onenumber, howmany, systemreset;
float money, lottocost, change, playrate, minimum;
char gambleagain;
time_t t;
// Assign values to (some) variables. Other assignments are made later.
t = time(NULL);
playrate = 0.75;
// Seed randomiser
srand(t);
/*
The following line resets the console, basically giving a blank screen.
The arguement (reset) passed to the funtion is UNIX/LINUX specific.
*/
/* system("reset"); I decided not to include this as it proved to be too troublesome when calling main() and I didn't want the system to reset. */
// This will display a 'user interface.'
printf("\n\n\t *****************************************\n");
printf("\t * Program to generate random *\n");
printf("\t * lotto numbers *\n");
printf("\t *****************************************\n\n");
// Inform user of program operaton and prompt for user input
printf("\n\t\t\t\t PLEASE NOTE:");
printf("\n\tMinimum play is 1.50 which will give you two sets of numbers.");
printf("\n\nHow much do you wish to spend? ");
// Accept user input - put it into the variable 'money'
scanf("%f", &money);
if (money<1.50) // Enforce minimum play of 1.50
{
printf("\n\n\n\n\t\t\t ***********************************\n");
printf("\t\t\t\a * Minimum amount to pay is 1.50. *\n");
printf("\t\t\t ***********************************\n\n\n\n");
main();
}
else
{
// Tell them how much they have chosen to spend
printf("You have chosen to spend %5.2f\n\n", money);
//The following code will generate all necessary code for randomised numbers
printf("Your numbers are:\n");
printf("******************************\n");
/*
The variable 'howmany' will contain a value based upon the division to the right which will determine how many times the 'setcounter' loop will loop.
*/
howmany = (money / playrate);
/*
Nested loops used. The inner loop (randomcounter) generates six random
numbers and the outer loop (setcounter) loops around according to the value
of the variable 'howmany' which in turn repeats the inner loop.
Initialise loop, compare to variable, and increment
*/
for (setcounter = 1; setcounter <= howmany; setcounter++)
{
for (randomcounter = 0; randomcounter <= 5; randomcounter++)
{
// Generate a random number between 1 and 42 and assign to 'onenumber'
onenumber = rand()%42 + 1;
// Print numbers to the screen
printf("%2d ",onenumber);
}
printf("\n");
}
printf("******************************\n");
// Finding the change to give back to the user
lottocost = (howmany * playrate);
change = (money - lottocost);
// Let the user know how much change they receive
printf("Your change is %5.2f\n", change);
// Ask them if they want to gamble again
printf("Do you wish to spend more money? (y/n) ");
scanf("%s", &gambleagain);
if (gambleagain =='y')
{
main();
}
else
{
printf("\n\n\n\t\t\t\tGoodbye!\n\n\n");
exit(1);
}
}
}