# Thread: lotto program in c

1. ## lotto program in c

Write an algorithm + a program in C that will allow us to play the “LOTTO
GAME”. For the purpose of the presentation of the assignment, you must be
able to show some winning outcomes (i.e. no randomness).
Every Saturday a draw is organized on TV. The “LOTTO GAME” is played as
follows:
Six numbers between 1 and 40 inclusive are generated at random. If a number
has been generated it is not generated a second time. A player can bet any six
numbers between 1 and 40 inclusive. The cost for each bet is MRs 20. A player
can bet as many times as he wishes for each draw. If the player gets all the six
numbers correct (the order is not important) he wins the jackpot. If more than one
player wins the six correct numbers the jackpot is shared equally among them.
The program should be able to record all the players, their bet and the total bet.
For five, four and three correct (again order is not important) betting consolation
prizes are awarded. Obviously as the number of correct numbers decreases the
number of potential winners increases and the prizes decrease also. You should
make use of functions in your program.
Each time the game is played a completely new and random set of six
numbers between 1 and 40 inclusive are generated.

this my code which i wrote
lottery
Code:
```#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<ctype.h>
#include<time.h>

void computerGenerator();
void winningNumbers();
void inputstring( char *inputptr );
void printarray(int * arrpt);
void playChoice();
void guess();
void ending();

char inputarray[512];
char *inputptr = inputarray;

int main()
{

char start;
srand(time(NULL));
int counter=0;
char choice;
int numPlay=0;
int lotto[6][5];
int r, c;

printf("                 Welcome to the lotto game!!\n");
printf("                 ------- -- --- ----- ------\n\n");
printf("This game asks you to pick six numbers or if you prefer\n");
printf("quickpick and then prints the winning number in ascending order\n\n");

printf("\tAre you ready to start?(y/n)  ", &start);
scanf("%c", &start);
fflush(stdin);

if (start == 'y')     // begin if "yes"
{
system("cls");
printf("How many games would you like to play? \n");
scanf("%d", &numPlay);
fflush(stdin);
system("cls");   // clear screen

printf(" Would you like to chose your own numbers, or are you lazy and want\n");
printf(" quick pick instead? \n\n Enter U for user input or Q for quickpick: ");
scanf("%c", &choice);
fflush(stdin);

if (choice == 'q')     // begin if "yes"
{
system("cls");
printf("Your quick pick numbers are: \n");
printf("---- ----- ---- ------- ----\n");
for( counter=numPlay; counter > 0;  counter--)
{
computerGenerator();
}//end for
}    //end if
else
{
system("cls");

for(r=0; r<numPlay; r++)
{
for(c=0; c < 6; c++)
{

scanf("%d", &lotto[c][r]);
}
}  //end for r

system("cls");
printf("Here are your %d hand-picked numbers:\n", numPlay);
printf("---- --- ---- - ----------- --------\n");
for(r=0; r<numPlay; r++)
{
for(c=0; c < 6; c++)
{
printf("%2d ", lotto[c][r]);
}

printf("\n");
}  //end for c
}// end for

winningNumbers();

} //end if
else                // begin if "no"
{
system("cls");   // clear screen
printf("\n\n\n\n");
printf("\t     Aww...you don't want to try my program?\n");    // ending
printf("\tWho needs you anyway, huh? Go buy a real ticket.\n\n");
printf("\tAnother project brought to you by Me\n\n");
}   // end else

printf("\n");
system("PAUSE");
return 0;

}   //end main

void inputstring( char *inputptr )
{
while ( ( *inputptr++ = getchar() ) != '\n' )
{
//printf("%c", (*inputptr));
}
//        printf("\n");
*( --inputptr ) = '\0';
}

void computerGenerator()
{
int array[6]={0};
int arrlen;

arrlen = sizeof(array)/sizeof(int);

for(int x=0; x < arrlen; x++ )
{
array[x] = (int) rand()%53+1;
for(int y=0; y<x; y++)
{
if (array[y] == array[x])
{
array[x] = (int) rand()%53+1;
y=0;
}  //if()
}   //for (y)
}  //for (x)

// sort array using swap and bubbles

for(int y=0; y < arrlen-1; y++ )
{
for(int x=0; x < arrlen-1; x++ )
{
if (array[x] > array[x+1])
{
int temp;
temp = array[x];
array[x] = array [x+1];
array [x+1] =temp;
}  //
}   //
}  //

printarray(array);
}   // end generator

void winningNumbers()
{
int array[6]={0};
int arrlen;

arrlen = sizeof(array)/sizeof(int);

for(int x=0; x < arrlen; x++ )
{
array[x] = (int) rand()%53+1;
for(int y=0; y<x; y++)
{
if (array[y] == array[x])
{
array[x] = (int) rand()%53+1;
y=0;
}  //if()
}   //for (y)
}  //for (x)

// sort array using swap and bubbles

for(int y=0; y < arrlen-1; y++ )
{
for(int x=0; x < arrlen-1; x++ )
{
if (array[x] > array[x+1])
{
int temp;
temp = array[x];
array[x] = array [x+1];
array [x+1] =temp;
}  //
}   //
}  //
printf("\n\nThe winning lotto numbers are: \n");
printf("--- ------- ----- ------- ---- \n");
printarray(array);
}   // end generator

void printarray(int*arrpt)
{

for (int x=0; x<6; x++)
{
printf("%2d ", arrpt[x]);
}
printf("\n");
}      // end printarray

void guess()
{
int play[6]={0};
printf("Enter the six numbers you want to play\n");
printf("Type them in separating by a space\n");

inputstring( inputptr );
system("CLS");
}

void ending()
{
int iochar;
printf( inputarray );
printf("\n");
}```

now am not able to stop duplicate of number in a single go
and am not able to write the code for the payment
example if a player win the jackpot the amount of money he wins depending on the number of games he play

2. For the numbers:
Lotto drops all numbers in a mill in order to scramble them. You can do the same by
(1) Make an array of size 40 and initialise its elements from 1 to 40 inclusive.
(2) Use the "rand()" function to generate two indices between 0 and 39 inclusive, and swap the contents associated with these indices.
(3) Do step (2) several times.
(4) Consider the first six elements of the array as the winning lotto sequence.

3. thank you for looking in my program.
can you please write the code for me..
its been a month since am trying to write the program
am going mad with the code..
i have to return my project in 2 days..
can you please write the code for me..

thank you.

4. Or you could just stop pretending you can program and just admit you're another useless copy/paste programmer who thinks they can get by with google searches and sob stories.

2004 on this site
Yet another lottery program
Apart from throwing in a few random blank lines, the code is the same.

At least then what you post will be your OWN effort, within the limits of your OWN understanding.
If you're not prepared to do this, just go back to your tutor and tell them you want to drop the course (before you get kicked off it anyway for either cheating or incompetence).

5. Originally Posted by vyshant
thank you for looking in my program.
can you please write the code for me..
its been a month since am trying to write the program
am going mad with the code..
i have to return my project in 2 days..
can you please write the code for me..

thank you.

Homework Policy

6. Code:
```#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
//Prototype
char randomNums(char * x, char y)
{
char z;
for(z=0;z<=6;z++)
if(x[z]==y)
return !0;
return 0;
}

//Start main
int main(void)
{
//Declare variables
char r1[6], r2[6];
char i,j;
char num;
char * l;
//Enter numbers and check conditions
for(j=0, l=r1;j<2;j++)
{
do{
num=0;
//Enter input
printf("\nEnter six numbers[Between 1 and 40]:\n");
for(i=0;i<6;i++)
{
scanf("%d",l+i);
if(*(l+i)>40 || *(l+i)<1) num = !0;
}
printf("\n");
//Check condition
if(num)
{
printf("Entered range numbers wrong. So give only between 1 and 40 .\n");
}
} while(num);
l=r2;
}
for(i=0;i<6 && randomNums(r1,r2[i]);i++);
{
if(i==6)
{
//Display the output
printf("YOU WON THE JACKPOT\n");
}
else
printf("Sorry..Better luck next time...\n");
getch();
}
}```
this one is my own program
what about helping me in this one

7. Originally Posted by vyshant
this one is my own program
what about helping me in this one
Of course. Firstly, try to implement what I described in post #2. Then, I believe everything will become clearer.

8. ## Well said!!

And U know what, the amazing fact is that this person is in my class..!

Thanks for showing him the right way..