Help in HEADBOB

can anyone please tell me whats wrong with my code?

problem: HEADBOB Problem - CodeChef

CODE: CodeChef: Practical coding for everyone

(i was planning to add break after the if statements, but anyways why is it giving me wrong answer?)

There is just one minor error in your code. And it is in the following statement: char a[n];

We know that, n is the number of gestures recorded for a single person. Now, you are declaring a character array of size n, and taking the input as cin >> a. You see where the error is? You have not accounted for the \0 or NULL character which marks the termination of a string.

Declaring a as char a[n + 1] will solve the problem.

I would suggest using std::string instead of C styled character array to avoid such mistakes in the future.

The same problem I was faced during my work and at that time programming assignment experts helping me in that situation I think you should contact them also for your query.