I have made this program to take in the first nine digits of a population registration number, and calculate the 10th.
The program works fine, as long as the modulus 11(method for the calculation) calculation do not return 121. In that case, the modus division returns 11....which shouldn't be possible, as it's being divided by 11, and is supposed to return 0.
Please take a look, and see if you can locate the problem.
Code:
#include <vcl.h>
#include <iostream>
#include <stdlib.h>
#pragma hdrstop
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
int Imod1, Imod2, Imod3, Imod4, Imod5,
Imod6, Imod7, Imod8, Imod9, Imod10, moddy;
char mod1[2], mod2[2], mod3[2], mod4[2], mod5[2],
mod6[2], mod7[2], mod8[2], mod9[2], mod10[2], input[12];
char* i = input;
cout << "Indtast cprnr. der skal udregnes ";
cin >> input;
strncpy(mod1, i, 1);
i += 1;
strncpy(mod2, i, 1);
i += 1;
strncpy(mod3, i, 1);
i += 1;
strncpy(mod4, i, 1);
i += 1;
strncpy(mod5, i, 1);
i += 1;
strncpy(mod6, i, 1);
i += 2;
strncpy(mod7, i, 1);
i += 1;
strncpy(mod8, i, 1);
i += 1;
strncpy(mod9, i, 1);
Imod1 = atoi(mod1);
Imod2 = atoi(mod2);
Imod3 = atoi(mod3);
Imod4 = atoi(mod4);
Imod5 = atoi(mod5);
Imod6 = atoi(mod6);
Imod7 = atoi(mod7);
Imod8 = atoi(mod8);
Imod9 = atoi(mod9);
moddy = (Imod1*4) + (Imod2*3) + (Imod3*2) + (Imod4*7) +
(Imod5*6) + (Imod6*5) + (Imod7*4) + (Imod8*3) + (Imod9*2);//modulus 11 calculation
Imod10 = moddy%11; //modus division
//cout << endl << moddy << endl;
Imod10 = 11 - Imod10; //could this line be the problem?
//cout << Imod10;
cout << "\n\nDit cprnr. er: " << Imod1 << Imod2 << Imod3 << Imod4
<< Imod5 << Imod6 << "-" << Imod7 << Imod8 << Imod9 << Imod10;
cin >> moddy;
return 0;
}
Hehe, sorry for keep editing this. I thought I located the problem, but I didn't