❔ How do I get around the out of bounds error when I submit this code?
25 Replies
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/BlazeBin - otkgbdkihzuq
A tool for sharing your source code with the world!
can you see what input it is thats giving out of bounds?
I think it's back2 = s[i - 2];
its giving the wrong result for
VII
btw
its saying 6, not 7yh ik
ill fix it once this stupid out of bounds error has gone
I've never seen this approach to a roman numeral converter before, can you walk me through the idea of the bounds check?
So essentially I wanted the algorithm to check what the digit before/ in front is. However with the constraints of length I needed it to not check for a value when there is no value there - e.g. checking for s[-1] as it doesn't exist. That's why I attempted to use the "bound check" too solve the problem.
it seems to get a bit confused on the very first and last ones, since for
VII
on the first iteration, back
is V
(which seems confusing)
ah okay so its just to prevent going OOB.. I see.I just realised I think I copied the wrong code
BlazeBin - ljhqfykuacxo
A tool for sharing your source code with the world!
that if statement is... quite something
try instead
also, instead of default to your current "digit", maybe let it default to something that wont ever be true
like
(char)0
I know Im a noob - I already tried to do that but it said that it couldnt implicitly convert it to an integer
then do it explicitly 🙂
Im sorry but how?
By reading the code sample I literally just sent?
Thanks - I still get the OOB error tho
did you fix the if statement?
yes
I rewrote your start to this:
and I'm not getting any OOBs
ah okay thanks, no OOB now
I still think this is a very... unique approach to roman numerals. Let me know if you want some tips.
okay, thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.