This is my first post so if I break any rules please just let me know.
I am a beginner in C and wanted to write a program similar to a game of Keno. It lets you self pick or auto pick the amount of numbers you desire to play and then compares your ticket to the winning ticket. So far it works great, but I know of two ways to break the code and want to fix it up.
Using the following to generate auto-pick numbers works fine:
srand(time(NULL));
if(pick==0)
{
for(j=0; j<x; j++)
{
y[j] = rand()%75+1;
printf("Number %d: %d\n", j+1, y[j]);
}
}
However, I would like to make sure that a number isn't accidentally picked twice, and if it is, for the program to select a new number.
In the self-pick loop, I would like to add a parameter that will not let the user pick a number outside of the range 1-75, and if they do, to instruct them to pick another. Here is the code for that loop:
if(pick==1)
{
for(j=0; j<x; j++)
{
printf("Pick a number between 1 and 75:");
scanf(" %d", &y[j]);
}
for(j=0; j<x; j++)
{
if(j==0)
{
printf("\n");
}
printf("Number %d: %d\n", j+1, y[j]);
}
}
If anyone could offer a hint or some things to think about when adding those bits to my code, or if you have any other suggestions, I would greatly appreciate it. Thanks!
Aucun commentaire:
Enregistrer un commentaire