2
I’m a beginner in C
And I’m having problems in an exercise, I can’t see a way to solve it.
Following:
In each stage the player has 2 balls with which to knock down 10 pins. The stage ends when: the player knocks down the 10 pins or the player uses the 2 balls.
i = bola1;
j = bola2;
pontuação
1 – STRIKE se i = 10 (a 2a bola não é usada);
2 – SPARE se i < 10, mas i + j = 10;
3 – MISS se i + j < 10;
Valor pontuação
STRIKE - 10 + números de pinos que o jogador derrubar com as duas bolas seguintes.
SPARE - 10 + número de pinos derrubados com a próxima bola
MISS - i + j
a) Leia uma seqüência de números inteiros que descreve um jogo completo. O i-ésimo termo da sequência é o número de pinos derrubados pela i-ésima bola. Qual será o tamanho máximo da seqüência?
b) Identifique a quantidade de pinos derrubados por cada etapa e classifique como STRIKE, SPARE ou MISS.
c) Calcule o número de pontos por etapa
d) Calcule o total de pontos no jogo
e) Imprima os resultados
Numero de exemplo;
1o jogo: 10, 9, 1, 6, 3, 7, 0, 8, 2, 0, 8, 2, 0, 8, 2, 0, 8, 1, 0, 9, 1;
2o jogo: 9, 1, 0, 10, 10, 10, 6, 2, 7, 3, 8, 2, 10, 9, 0, 9, 1, 2;
3o jogo: 10, 9, 0, 8, 2, 10, 10, 7, 3, 4, 6, 10, 9, 1, 10, 7, 3;
Well, I tried to use one for
to check the value of each vector position, so far so good, my problem is to compare the next two values if the first is not a Strike.
main() {
int game1[20] = {10, 9, 1, 6, 3, 7, 0, 8, 2, 0, 8, 2, 0, 8, 2, 0, 8, 10, 9, 1};
int game2[18] = {9, 1, 0, 10, 10, 10, 6, 2, 7, 3, 8, 2, 10, 9, 0, 9, 1, 2};
int game3[17] = {10, 9, 0, 8, 2, 10, 10, 7, 3, 4, 6, 10, 9, 1, 10, 7, 3};
int i, j;
for(i=0; i<20; i++) {
for(j=0; j<20; j++) {
if(game1[i] == 10) {
printf("Strike");
}
}
}
}
This is the code I started to do, but my doubt is more in the logical part, how to compare the value of i and j to know if it is a Strike, Spare or Miss;
Edit your question and post the code you already tried for the staff to help you, ;)
– Franchesco
edited, thanks ^^
– YutoSan
I do not see why to use 2 is, just 1 and follow its logic: if Game1[i] = 10 then it is strike, otherwise if Game1[i] + Game1[i+1] = 10 then it is Spare, and so it goes. All you have to do is look at Game1[i + 1], because it will burst the vector when it is at the end, so you have to check.
– Luis Henrique
I tried the way you said Read More, it even worked, but, for example, after comparing the first 10, it goes on to compare the 9 with the 1, and then the 1 with the 6. After comparing the 9 with the 1 it compares the 6 with the 3 respectively. I don’t know if I understand it. But your answer has already given me a good light here. Thank you ^^
– YutoSan