Ok so i made a program in c that is asking the user to choose 1 of 4 stages he would like to play in. After the user chooses the stage, the program is generating a secret code that built out of 4 chars and its between 1-6 (for example- 3516). But i wanted to make the chars non-duplicated, so there will be no 2 numbers the same (for example- 1642 its good but 6632 its bad code). After i made a few "if"s in my code and i ran it, it just stacked. This is my code:
#include <stdio.h>
#include <stdlib.h>
int getStages();
int randCode();
int main()
{
getStage();
system("PAUSE");
}
int getStage()
{
int choice= 0;
printf("What stage would you like to choose? Choose Wisely: ");
scanf("%d", &choice);
randCode();
}
int randCode()
{
srand(time(NULL));
int randFirst= rand() % 6 + 1;
int randSecond= rand() % 6 + 1;
int randThird= rand() % 6 + 1;
int randFourth= rand() % 6 + 1;
while(randFirst = (randSecond || randThird || randFourth))
{
int randFirst= rand() % 6 + 1;
}
while(randSecond = (randFirst || randThird || randFourth))
{
int randSecond= rand() % 6 + 1;
}
while(randThird = (randFirst || randSecond || randFourth))
{
int randThird= rand() % 6 + 1;
}
while(randFourth = (randFirst || randSecond || randThird))
{
int randFourth= rand() % 6 + 1;
}
char firstNumber= randFirst;
char secondNumber= randSecond;
char thirdNumber= randThird;
char fourthNumber= randFourth;
printf("%d %d %d %d\n", firstNumber, secondNumber, thirdNumber, fourthNumber);
}