Quote:
Originally Posted by gargolajr
How can i translate this function to C++ code?
|
I expect that means you haven't learned C yet either.
If you know even a little C, it should be easy to code that function in C. If you know even a little C++, you should know that function has no significant reason to be different in C++ from the same function in C.
But before coding, make sure you resolve the ambiguity in the problem statement:
Quote:
PARAMETER 3: An integer specifying the ending index
|
In C and C++ programming it is common, but not universal, to interpret an "end" index as the index of the first item not included, meaning one beyond the last item included. But it is also possible that an "end" index represents the last item included.
A good spec should make clear for any "end" pointer or index whether it means last included vs. one past the last included.
Quote:
Loop around until currentIndex is equal to ending index
|
That sounds like "end" means first not included, but it still is not clearly unambiguous (English rarely is). Do you know whether "end" is the last included vs. one past the last included?
Other than the above comments, I'm not going to do your homework for you.
If there is a specific detail of C++ syntax that is giving you trouble, please feel free to post what you have done so far and the specific question or problem that you have. But please do not ask for someone to do the entire assignment for you.
BTW, regarding my statement that this function would the same in C vs. C++, I want to add one qualification. I don't use C enough to even try to remember which versions of C restrict the declaration of local variables to places other than where good C++ style would place them. In my opinion, good C++ style usually includes declaring most local variables at the natural point where they first receive a value. In older versions of C, you may be forced to declare local variable earlier. In C++, you
can declare variables as if you were in an older version of C, but you
shouldn't.