1
I’m trying to make a vector with 23 names, which should draw 11 salts, 6 sweets and 6 drinks without repetition, the draw should be done in numbers 1 to 3 and when it is drawn should be assigned a value in characters, and at the end should be informed to the user the names and the item that was drawn.
The naming part is ok, but it ends without informing the items
#include <stdio.h>
#include <stdlib.h>
int main()
{
char nomes[23];
char itens[23];
int i,x,contador1,contador2,contador3;
char item[10];
int volta;
for(i=0;i<=22;i++)
{
printf("Digite o nome: ");
scanf("%s",&nomes[i]);
}
for(i=0;i<=22;i++)
{
volta = 1;
while (volta)
{
x = rand() % 3;
if((x==0) && (contador1<11))
{
strcpy(item,"salgado");
contador1 = contador1 + 1;
volta = 2;
}
else if((x==1) && (contador2<6))
{
strcpy(item,"doce");
contador2 = contador2 + 1;
volta = 2;
}
else if((x==2) && (contador3<6))
{
strcpy(item,"bebida");
contador3 = contador3 + 1;
volta = 2;
}
else
{
volta = 1;
}
}
itens[i] = item;
}
for(i=0;i<=22;i++)
{
printf("Aluno: %s ficou com: %s ", nomes[i], itens[i]);
}
getch();
return(0);
}