In the following code I have a char with 2 characters, H
( Heads
) and T
( Tails
), at the time of printing it will clearly print one of these 2 letters but I wanted to make a change and print "Face" or "Crown". How would I have to do this? Through a string vector? If so, how?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
char fc[2] = {'H','T'};
srand(time(NULL));
int i =0;
int j = 0;
char temp ;
int c;
printf("Nesse programa voce pode ver quantas vezes seria preciso para uma moeda cair X vezes do mesmo lado.\n");
printf("Digite quantas vezes em sequencia a moeda deve cair:\n");
scanf("%d",&c);
while(i < c){
char comp = fc[rand()%2];
if (j == 0){
printf("inicio\n");
temp = comp;
}
else if(temp == comp){
i++;
temp = comp;
printf("%c\n", comp);
}
else {
i = 0;
printf("%c\n", comp);
}
j++;
}
printf("Tentativas: %d\n", j-1);
system("pause");
return 0;
}
I have tried to make the following changes to the declaration and impressions:
char fc[2][10] = {"Cara", "Coroa"};
printf("%s" , comp);