Please help me finish this project. I am having trouble coming up with the code to ensure the numbers do not repeat. i made another post the other day, but this is what i have come up with since then. the output puts out the user entered amount of sets, but the numbers still repeat.
my instructor commented the code but i am still lost as to how to finish the code.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#define OFFSET 1
#define RANGE 53
void Flush(void);
int GetRandomInRange(int offset, int range){
int num = (rand() % (range - offset + 1)) + offset;
return num;
}
void PrintRandomSet(int a, int b, int c, int d, int e, int f){
int i;
printf("%2d %2d %2d %2d %2d %2d\n" , a, b, c, d, e, f);//minimum width makes it align
//}
return;
}
int PrintInstructions(void){
int numSets = 0;
int success = 0;
char c;
for(;;)
{
printf("******************************************************************\n");
printf("Enter the amount of sets of 6 random numbers you want to generate.\n");
printf("Enter in 'q' or 'Q' to quit...\n");
printf("******************************************************************\n");
success = scanf(" %d" , &numSets);
if(success == 0)
{
scanf(" %c", &c);
if(tolower(c) == 'q')
return -1;
}
else
return numSets;
}//end for
}
int main(void) {
int a;
int b;
int c;
int d;
int e;
int f;
int i;
srand(time(NULL));
int numSets = 3;
do{
//PrintInstructions();
numSets = PrintInstructions();
if(numSets > 0)
{
for(i=0; i<numSets; i++)
{//you need a block of code here for compound statements
a = GetRandomInRange(OFFSET, RANGE);
b = GetRandomInRange(OFFSET, RANGE);
c = GetRandomInRange(OFFSET, RANGE);
d = GetRandomInRange(OFFSET, RANGE);
e = GetRandomInRange(OFFSET, RANGE);
f = GetRandomInRange(OFFSET, RANGE);
PrintRandomSet(a, b, c, d, e, f);
}//end for
}//end if
}while(numSets != -1);//Yuor do while syntax was wrong.
printf("You have chosen to quit");
return 0;
}
void Flush()
{
char c;
while((c = getchar()) != '\n' && c != EOF);
return;
}