How to create an array with roulette colors?

1

#include<stdio.h>intmain(void){charcor[35];//declararvetorpararecebernomedascoresintnumeros[35]={0};//declararvetorparareceberonumerorespectivodascoresinti=0;intentrada;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, but I do not know how to proceed any more.

    
asked by anonymous 13.05.2016 / 23:19

1 answer

3

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

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

Colors must have a pattern indicating how each number is represented. I created an array with a character representing the color at the position of each number. The array must have 37 positions because it goes from 0 to 36. The 0 is green, so differentiation treatment deserves treatment. I did not follow the colors on the roulette image. If this is important, just change the order in the array , each character is a position. An array that is a string is a string so it became easier to declare it as such. Strictly there is a slight technical problem in doing this, but it will not affect the operation on something so simple.

Once typed the value gets the position of the array according to the typed one to choose the color and decide what to write. Then take the rest of 2 to see if it is even and check if the number is greater than 18, but I do not know if this is correct.

It does not have the statement, but I checked if an invalid value was entered, because without it, it would give code problem.

#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");
}

See running on ideone and on CodingGround .

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

    
14.05.2016 / 01:04