Overclock.net banner

1 - 2 of 2 Posts

·
Registered
Joined
·
1,576 Posts
Discussion Starter #1
Here my the program

Code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 10

void setseed();
int genNum();
void quickPick(int *, int);
void userEnter(int *, int);
int genEncore();
void sortNum(int *, int);

int main()
{
int choice = 0;
int tickets = 0;
char encore;
int numEncore = 0;
int j = 0;
int k = 0;
int numbers[MAX];
int total = 0;

setseed();

fprintf(stdout, "Welcome to Lotto 649! How many tickets would you like?\
Choice: ");
scanf("%i", &tickets);

        fprintf(stdout, "Would you like encore? Y/N\
Choice: ");
        scanf("%c", &encore);
        scanf("%c", &encore);

fprintf(stdout, "Please choose one of two options\
1. Quick Pick or\
2. User Input\
Choice: ");
        scanf("%i", &choice);

for(j = 0; j < tickets; j++)
{
if(choice == 1)
{
quickPick(numbers, MAX);

if(encore == 'y' || encore == 'Y')
{
numbers[7] = genEncore();
total = total + 3;
}
else if(encore == 'n' || encore == 'N')
{
fprintf(stdout, "You have chosen no encore.\
\
\
");
total = total + 2;
}

for(k = 0; k < 6; k++)
{
fprintf(stdout, "%i\", numbers[k]);
}

fprintf(stdout, "Bonus: %i\", numbers[6]);
fprintf(stdout, "Encore: %i\\
", numbers[7]);

}
else if(choice == 2)
{
userEnter(numbers, MAX);

if(encore == 'y' || encore == 'Y')
{
numbers[7] = genEncore();
total = total + 3;
}
else if(encore == 'n' || encore == 'N')
{
fprintf(stdout, "You have chosen no encore.\
\
\
");
total = total + 2;
}

for(k = 0; k < 6; k++)
{
fprintf(stdout, "%i\", numbers[k]);
}

fprintf(stdout, "Bonus: %i\", numbers[6]);
fprintf(stdout, "Encore: %i\\
", numbers[7]);

}
else
{
printf("Invalid choice! Try again later.\
");
}
}

fprintf(stdout, "Your total is $%i\
", total);

return 0;
}

void setseed()
{
int seed; // time(0) returns the current clendar time, often
seed = time(0); // implemented as # of seconds since some specified
srand(seed); // date. sets different seed each time, making random output appear even more random
}

int genNum()
{
int num;
num = rand() % 40 + 1;
return num;
}

void quickPick(int c[], int i)
{
for(i = 0; i < 7; i++)
{
c[i] = genNum();
}

sortNum(c, i);
}

void userEnter(int d[], int i)
{

for(i = 0; i < 7; i++)
{
printf("Enter number for number %i: ", i + 1);
scanf("%i", &d[i]);
} 
}

int genEncore()
{
int num;
num = rand() % 9999999 + 1;
if(num < 1000000)
{
genEncore();
}
return num;

}

void sortNum(int e[], int i)
{
int temp;
int ctr1;
int ctr2;
for(ctr1 = 0; ctr1 < 5; ctr1++)
{
for(ctr2 = (ctr1 + 1); ctr2 < 6; ctr2++)
{
if(e[ctr1] > e[ctr2])
{
temp = e[ctr1];
e[ctr1] = e[ctr2];
e[ctr2] = temp;
}
}
}
}
Ok basically for the quick pick function I have in this program, I need to make sure no duplicate numbers are generated, how would I go about adding that?

Also any other tips on how I could improve this program?

Thanks
 

·
Registered
Joined
·
784 Posts
if you had some way of keeping track of what numbers were previously selected you could tell your program to keep looping until a new unique number is drawn...

I dont want to give it completely away but that should help you a little.
 
1 - 2 of 2 Posts
Top