Onboarding - Puzzle discussion

I suck in Java but I was able to solve it.

I originally came to this site because it was marketed as a way to LEARN to program, which I have been interested in for a while, but upon getting here and attempting to do the tutorial and then reading this forum I see that this is not the case. I thought the idea of this site was great when I heard it but it seems that it is completely useless unless you already know how to program.

Learn to program while solving puzzles.

Ok, so. I have the program outputting the name of enemy1, if the distance is less than that of enemy2, and outputting the name of enemy 2 otherwise. after the first couple shots, it just stops. Any thoughts?

Got it figured out, nvm :slight_smile:

Iā€™m getting this message when I try to run test case :ā€œTimeout: your program did not provide an input in due timeā€. Iā€™m not sure what it means, and how to handle it. Please help

you dont process all the conditions in your program, in some of them you donā€™t have output

I finished the tutorial without trouble once I stopped overcomplicating things and just followed the directions, but Iā€™m just learning C++ and I want to know why it works. Could somebody explain how:
string enemy1; // name of enemy 1 cin >> enemy1; cin.ignore(); int dist1; // distance to enemy 1 cin >> dist1; cin.ignore();

was able to identify the enemy in the game information?

enemy1 and dist1 are inputs given by CodinGame each round.

cin (http://www.cplusplus.com/reference/iostream/cin/) is used to read these input.

im noob. the only attacks or shots i use is with
Print(ā€™ā€¦ā€™)
can u help me with extra commands or something for in JavaScript??

You need to know what an ā€œIf statementā€ is, and how to compare two numbers.

Thatā€™s probably the first chapter of every tutorial/manual/book in every programming language.

try just a succession of scanf and printf of pointer and it will works for test 1

exemple
char *enemy1
char *enemy2
int dist1;
int dist2;

scanf("%s", &enemy2);
scanf("%d", &dist[0]);
printf("%s\n", &enemy2);
scanf("%s", &enemy1);
scanf("%d", &dist[0]);
printf("%s\n", &enemy1);

Iā€™m on the first puzzle and writing an ā€œifā€ statement is pretty easy but the ship does not react. Do I need to compile my code somehow on the IDE and then run the game? Or does the syntax have to be specific?

if ( dist1 < dist2 ) {
cout<<"Enemy = "<<enemy1<<endl;
}
else etcā€¦

1 Like

tell me how to do it!!!

From what I can see, your output seems wrong. You have to output only the value of either enemy1 or enemy2. Followed by a newline.

You can help me? I m a beginnen. Sorry.:wink:

Hi,
Iā€™m trying the first puzzle in C++, but it seems I cannot get anything printed to the console. (Iā€™m on Firefox)
I tried just printing things:
cerr << ā€œDebug messagesā€¦ā€;
cerr << ā€œname 1:ā€+enemy1;
cerr << ā€œname 2:ā€+enemy2;
but even this doesnā€™t print anywhere. It should print in the console output, right?
Am I missing something? Do I need to save or compile the code?

Hey, Iā€™m working on ā€œImminent Dangerā€ in Javascript. I used the provided skeleton code and formatted it. The test runs, however, and ā€œRockā€ always gets through and kills me, even though the ship is killing other ships the entire time. Is it because ā€œRockā€ is only a single ship, and the code compares two ships?

It looks like you are missing a newline to flush the stream.

Hey @ShadiMirza,

Rock should be the first one you kill. Arenā€™t you killing the farthest one, instead of the closest one?