0
In the following code I have a char with 2 characters, H
(Heads
) and T
(Tails
), at the time of printing will clearly be printed one of these 2 letters, but I wanted to make a change and print "Heads" or "Tails". In what way would I have to do that? Through a string array? If yes 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 statement and to the impressions:
char fc[2][10] = {"Cara", "Coroa"};
printf("%s" , comp);
Only
srand((unsigned)time(NULL));
would be sufficient to initialize the pseudo random number generator from the time of the system. The functiontime()
supports null parameter.– Lacobus
Edited, thank you.
– Cloud