Thanks for the reply. I was using spaceY because after the first pass, my ship would always fire just before or just after a mountain, meaning that my spaceX variable wasn’t updating correctly. So I tried t update the spaceX variable based on whether my pass was even (moving to the right), or odd (moving to the left). That was why I wanted the modulo.
And at least in Javascript, mountainH[i] does not work.
Ok, I solved it, but I did have to create an array. I iterated the heights of all the mountains, pushed those into an array, pulled out the math.Max from that array, then pulled the indexOf the highest value. I don’t see how I could simply save the index of the highest mountain without an array.
I’ve done, I’ve done it…!!!=) Thanks for tips they were very useful. I just wanted to ask how i could take these tasks without using an additional array.
I dont unterstand how this really works. I try to get the highest mountain für each altitude (10,9,…). So in the for-loop I do something like:
for (int i = 0; i < 8; i++) {
int mountainH; // represents the height of one mountain, from 9 to 0. Mountain heights are provided from left to right.
scanf("%d", &mountainH);
if(mountainH > height){
height = mountainH;
highest = i;
}
}
so I get the highest mountain. BUT only in altitude of 10 the Mountainnumber contains to the spaceX-coordinate. Why?
For example I have only one Mountain. This is Mountain 3. Then I do this:
if(spaceX == highest) {
printf("FIRE\n");
}
BUT why this is only working für altitude of 10. In all other Altitudes the Spaceship fires wrong…
If it only works the first turn (at altitude 10), you are probably not resetting hight. On the second turn (at altitude 9) it’s like you are looking for a mountain higher than the highest mountain of the first turn, but there isn’t any.
When spaceX is 2 and heightest which is triggered by being over the index of the mountain (index 3), the ship fires. This makes no sense, the if statement is not triggering with the correct statement.
I am in stuck with test case 5: “Your spaceship is over mountain 4, your altitude is 9
You tried to fire, but you cannot now. Your cannons are not fully recharged yet”.
Any ideas?
Thanks. I finally figure out my problems. I have checked algro again: find highest moutain with cell cooordinate same spaceX, and then shoot it first per turn.