How do I use an "or" in while in C [closed]

0

I'm trying to make a naval battle application with which the while stops with 2 conditions, which are the errors or hits of the player, where he can err 5 times and have to hit all points, which in this case is 30.

        do{
    mostrarTabuleiro();
    tiro();
    system("pause");
    system("cls");
}while (erros<5||acertos<30);

I wanted to know if it is some syntax error or if the error is before that part.

void tiro()
{
    int i,j,teste,cont;

    SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY);
    printf("\nVAMOS ATIRAAR!!\n");
    printf("Digite a linha: ");
    scanf("%d",&i);
    printf("Digite a coluna: ");
    scanf("%d",&j);
if (tabuleiro[i-1][j-1]!=-1)
{
    printf("Nao desperdice seu tempo!!\n");
    printf("Digite uma coordenada válida!\n");
}
else if (tabuleiro[i-1][j-1]==-1)
teste=navios[i-1][j-1];
acertos=0;
erros=0;
switch (teste)
        {
        case 1:
            erros=erros+1;
            tabuleiro[i-1][j-1]=teste;
            printf("VOCE ERROU\n");
            break;
        case 2:
            tabuleiro[i-1][j-1]=teste;
            acertos=acertos+1;
            printf("Voce acertou um Submarino (2 espaços)\n");
            break;
        case 3:
            tabuleiro[i-1][j-1]=teste;
            acertos=acertos+1;
            printf("voce acertou um contratorpedeiro (3 espaços)\n");
            break;
        case 4:
            tabuleiro[i-1][j-1]=teste;
            acertos=acertos+1;
            printf("voce acertou um navio-tanque (4 espaços)\n");
            break;
        case 5:
            tabuleiro[i-1][j-1]=teste;
            acertos=acertos+1;
            printf("voce acertou um porta-aviões (5 espaços)\n");
            break;
        }
}

Here is the void shot, where the stop condition is.

    
asked by anonymous 12.06.2017 / 14:01

1 answer

-1

I think your problem is in the shooting method, it is within a "do while", whenever you enter the method and the user enters a valid coordinate these to do:

else if (tabuleiro[i-1][j-1]==-1)
teste=navios[i-1][j-1];
acertos=0;
erros=0;
switch (teste)
  (...)

Each time the user enters the correct coordinates, returns to put the values to 0 in the next iteration, so, your variable hits and errors will always have the value 0 and 1, never higher than that which makes a cycle infinite.

To facilitate, you can substitute the values:

acertos=acertos+1;
erros=erros+1;

By:     hits ++;     errors ++; That increments 1 the variable, if you want to increment another value you can do:     hits + = x;     + = x errors; If x is a value of your choice, the + = substitutes:

Variable = Variable +

    
12.06.2017 / 15:41