0
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
int main(){
int nSorteado[6];
int i, j, n1, n2, op, seq[6];
int Ncorretos=0, pontos=0, seg;
srand(time(NULL));
setlocale(LC_ALL, "Portuguese");
system("color F4");
for(i=0; i < 10; i++)
{
printf("############### JOGO DA MEMÓRIA #################");
printf("\n*\n* Escolha um intervalo de números: ");
scanf("%d %d", &n1, &n2);
printf("*\n");
printf("* Embaralhando os números de %d a %d...\n*", n1, n2);
for(i=0; i < 6; i++)
{
nSorteado[i] = n1 + rand() % (n2-n1+1);
}
printf("\n* Voce tem 5 segundos para decorar os 6 números.\n\n");
for(i=0; i < 6; i++)
{
printf("%d ", nSorteado[i]);
}
seg=5;
do
{
printf("\n\n%ds",seg);
if(seg==20)
{
seg=0;
}
Sleep(1000);
seg--;
}while(seg>0);
system("cls");
printf("\nQual foi a sequencia dos 5 números sorteados?\n");
printf("\n*Obs:. Digite os números com espaço entre eles. Ex: 1 2 3 4 5 6.\n\n");
for(i=0; i < 6; i++)
{
scanf("%d", &seq[i]);
if(seq[i] == nSorteado[i])
{
Ncorretos++;
}
}
if(Ncorretos == 6)
{
printf("Parabéns!! Você acertou!");
}
else
{
printf("Errado! Tente novamente...");
}
Sleep(1000);
system("cls");
}
return 0;
}
Note: Every time the code is executed, it generates 6 random numbers. The first time the code is executed and the user enters the correct sequence of the numbers, he receives a message of "Congratulations", but the other times that the user type the correct sequence, he receives an error message. I have tried several ways to tidy up but it did not work out the game work normally. If anyone can help me I really appreciate.
https://answall.com/q/390787/101 e https://answall.com/q/41829/101
– Maniero
This answers your question? Generate random numbers that do not repeat
– Rebeca Nonato