How to create an array of roulette colors?

Asked

Viewed 321 times

0

#include <stdio.h>

int main (void)

{

    char cor[35]; // declarar vetor para receber nome das cores
    int numeros[35] = {0}; // declarar vetor para receber o numero respectivo das cores
    int i = 0;
    int entrada;

    for (i = 0; i <= 35; i++)
    {
        printf(" DIGITE O NUMERO: ");// atribuir os valores, neste caso de 0 a 35
        scanf("%i", &numeros[i]);
        i = i++;
    }
    i = 0;
    for (i = 0; i <= 35; i++)
    {
        printf(" DIGITE AS CORES EM SEQUENCIA: ");// atribuir as cores com os numeros respectivos em sequencia de 0 a 35
        scanf("%c"&cor[i]);
        i = i++;
    }

    i = 0;

    printf(" DIGITE QUAL NUMERO VOCE DESEJA: ");// entrada do usuario
    scanf("%i"&entrada);
}

I’ve done something like this only I don’t know how to go on.

  • Did the answer solve your problem? Do you think you can accept it? If you don’t know how you do it, check out [tour]. This would help a lot to indicate that the solution was useful to you and to give an indication that there was a satisfactory solution. You can also vote on any question or answer you find useful on the entire site.

1 answer

3

This code does not seem to have anything to do with the statement. I wrote a code according to what I understood.

Whether it is large or not, even or odd can be discovered by normal checking using comparison is pure mathematics.

Colors need to have a pattern indicating how each number is represented. I created a array with a character representing the color at the position of each number. The array needs to have 37 positions because it goes from 0 to 36. 0 is green, so it deserves treatment differentiation. I didn’t follow the colors that are in the roulette image. If this is important, just change the order arranged in the array, each character is a position. A array which is a string is a string then it’s easier to declare like that. Strictly there is a slight technical problem in doing this, but it will not affect the operation on something so simple.

After typed the value is picked the position of the array according to the typed to choose the color and decide what to write. Then take the rest of 2 to see if it’s even and check if the number is over 18, but I don’t know if this criterion is correct.

It does not have in the statement, but I checked if an invalid value was typed, even because without it, it would be a problem in the code.

#include <stdio.h>

int main(void) {
    char cor[37] = "0PVPPVPVVVPPVPVVVVPVPPVPVPPVPVPVPPVPV";
    int entrada;
    printf("Qual é o número? ");
    scanf("%i", &entrada);
    if (entrada < 0 || entrada > 36) { 
        printf("Valor inválido");
        return 0;
    }
    printf("\nO número é %d, é %s", entrada, cor[entrada] == 'V' ? "vermelho" : cor[entrada] == 'P'
                                                                 ? "preto" : "verde");
    printf(", %s", entrada > 18 ? "grande" : "pequeno");
    printf(", %s", entrada % 2 == 0 ? "par" : "ímpar");
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

So the code was much simpler than what was being tried. I start by interpreting the text correctly. Then have a mathematical understanding of things. When coding the least you need to know is the syntax of things. The written code had several problems and did not even compile. Even if the logic was this described code year, it still has other logic problems besides syntax errors.

  • 4

    Doing her homework? ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.