Valuation - piece of code won't work
Posted: Sun Nov 16, 2008 3:28 pm
Hi there,
to solve 'Valuation', I've written a small piece of C#-code.
arrText is an array consisting of 256 char-elements read from a text-file. This data seems to be correct. The output is everytime '1295', but it won't work.
Can someome give me a hint?
Thank you.
to solve 'Valuation', I've written a small piece of C#-code.
Code: Select all
static int recalc(int dx) {
return dx - 48;
}
[...]
while(cnt < arrText.Length) {
if (false == Char.IsDigit(arrText[cnt])) { // if 'x' occurs, set it to zero and move left
arrText[cnt] = '0'; // write ASCII-'0' as char ('48' in dec)
cnt -= 2; // go two steps left
}
int x = recalc((int)arrText[cnt]); // casting from char to int delivers ASCII-value in dec. To get the digit itself, recalc() subtracts 48 from each value.
sum += x;
cnt++;
}
Can someome give me a hint?
Thank you.