0
I’m trying to make a naval battle application with the while stop with 2 conditions, which are the player’s mistakes or hits, where he can miss 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’s 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 shooting void, where this the stopping condition.
Your condition
do_while
is correct. Run the program with a Debugger to know the error line.– Francisco
You could try to separate the operator, like this: while (errors < 5 || correct answers < 30), or even like this: while ((errors < 5) || (correct answers < 30))
– Roberto de Campos
There is no syntax error in the code, although little readable, unless the functions and variables involved do not exist. What error occurs? Where? needs more context, looking at just this can not know.
– Maniero