6 つのランダムな人間の文字と 6 つの乱数を生成するコードに問題があります。これが私のコードです。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char name[5] = {'Daniel','Bill','Ben','Steve','Drew'};
char animals[5] = {'Dog','Cat','Mouse','Chicken','Bird'};
int age[5] = {25,17,18,50,10};
char city[5] = {'Palo Alto','Escondido','Chicago','Mumbai','Zapopan'};
int main() {
srand(time(NULL));
int a = rand(),b = rand(),c = rand(),d = rand(),e = rand(),f = rand();
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[a],animals[a],age[a],city[a]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[b],animals[b],age[b],city[b]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[c],animals[c],age[c],city[c]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[d],animals[d],age[d],city[d]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[e],animals[e],age[e],city[e]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[f],animals[f],age[f],city[f]);
return 0;
}
うまくいかないようです S: 私は初心者ですが、誰か助けてくれませんか?
ありがとう!