Victor Bazarov said:
muser said:
[...]
string1[0] = string[0] - 0;
string1[1] = string[1] - 0;
string1[2] = string[2] - 0;
string1[3] = string[3] - 0;
string1[4] = string[4] - 0;
Subtracting 0 from anything usually doesn't do anything. Do you
really think it does? What do you think you're accomplishing here?
product = (string[0] * 5) + (string[1] * 4) + (string[2] * 3) +
(string[3] * 2);
Why are you multiplying by 5, 4, 3, and 2 here? What happened to
string[4]? How come it's not participating?
remainder = (product % 11);
What is that for?
checkdigit = (11 - remainder);
What is that supposed to do?
if(string1[4] != checkdigit){}
What are the curly braces after the 'if' expression?
return false;
return true;
}
I have tried putting the zeroes in single quotation marks e.g. '0'.
And putting brackets around the equation string1[0] = (string[0] - 0);
the string contains numbers 24686, the last digit is a six, and the
checkdigit is a six, so the function is suppose to return true, but
doesn't. It returns false.
Wow... You _have_ tried everything. I don't even know what to suggest.
To be honest with you, I see NO HOPE for you. You should stop wasting
your time. Go paint, or play guitar, or ... In any case, programming is
simply not your thing. Once you realise that, you'll be free.
I had been thinking the same thing victor, (that is to give up and
quit) but now that I've put in so many hours and come this far, I
can't let go like the proverbial dog who has got hold of a bone and
won't let go.
You see if I get this part of the program to work, I will have
finished this part of the course and could in all fairness give up.
What frustrates me is that the code should work and doesn't.
My assignments is this, if you had a load of customers, but wanted to
identify them by code alone you might use a customer code.
(rec.Newcrecord.customercode)These codes are held on a file along with
other customer details from different departments. Some of the
customer codes held on file are wrong, so there is a formula for
checking whether a customer code is right or not.
You * the customer code by a weighting factor (in this instance 5432)
the last customer code digit is a 6, but for the purposes of the
formula it isn't used when validating the customer code.
say customer code is 2468
****
and the weight 5432
the product of this would be 10 + 16 + 18 + 16 = 60;
so the product actually equals 60.
This is then divided by 11 (because all the valid customercodes will
have a modulus 11 checkdigit)
remainder = product % 11;
This produces 5;
subtracting 11 (our mod number) with the remainder gives us 6.
6 being our check digit.
if(string[4] != checkdigit){
return false;
}
or if(string[4] != checkdigit)
return false;
I should have clarified what it was I was trying to achieve.
For all intent purposes when I debug the function
CheckDigitForCustomerCode( char* string )
the product variable contains 60;
the remainder variable contains 5;
the checkdigit variable contains 6;
But the thing is, is that when I go to execute the program my valid
customer code of 24686, comes up as invalid.
I would like to know what could possibly cause this to happen.
string1 is of type integer. string is of type char.
If this or my post is frustrating any members of the newsgroup please
feel reassured that it isn't frustrating you half as much as it is me.