Check Digits and extracting digits

Posted on 16th Feb 2014 by admin

I think I can figure out the code for this but I am having a very hard time getting past the first step. Any suggestions are greatly appreciated.

What I need to do is take a 9 digit account number (for an electrical bill) and 1) determine if it is a valid account using the check digit, and 2) determine the type of account it is (ie if the 2nd digit is a 4, its a residential account).

Suppose the account is 123456789 and I need to add the 3rd, 5th, 7th, and 9th digits, how to do I extact the digits so they can be worked with? All I can think of is to do something like this:

cout << "enter the third digit of your account"
cin >> digit3 >> endl;
cout << "enter the fifth digit..."
cin >> digit5 >> endl;

and so on...

total = digit3 + digit5 + digit7 + digit 9

Its obviously not practical to have the user enter their account number one digit per line as I am doing But how else do it make the account number into something I can manipulate?

I am a beginner. And not a very smart one, obviously :(

Other forums