I need to create a program that will find account number and verify them I'm stuck though!!!

I need to create a program that will looking into a text file and read numbers out of the text file and then see if they are correct or not. For example, given the account number:  123456786  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 36 and 6 is the rightmost digit of 36, therefore the account is valid. While also I need to check to see if it is illegal meaning there is a space in the number.

The sample Input:
  123456786
  123456789
  12343546

Output produced byt eh Sample Input:

Acct #:  123456786 is Valid.
Acct #:  123456789 is Invalid.
Acct #:  12343546 is Illegal.

If you could please help me with this I would appericate it. Thanks
FosheeJoshAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
Sounds like homework.

This isn't hard to do.  Post what code you have here and we'll criticise and help.  But not give a complete solution for it.
FosheeJoshAuthor Commented:
Well I'm trying first to even get it where it will read one  line of the account number and then I can read another file and get it so that I can tell if it is valid or not. But I get a running time error every time I try it. Here is my code so far

Program AccountNumbers (Input, Output, accounts, mainaccounts);
Var
  accounts:text;
  mainaccounts:text;
  num:char;
  num2:real;
  accnum:real;

begin
assign(accounts, '/home/rd/rd013/programs/prog7/accounts.txt');
assign(mainaccounts, 'home/rd/rd013/programs/prog7/mainacocunts.txt');
reset (accounts);
 while (not eof(accounts)) do
   begin
    rewrite(mainaccounts);
    while (not eoln(accounts)) do
     begin
      read(accounts, num);
      writeln(mainaccounts, num2);
     end;
    readln(accounts);
   end; {while not eoln}
reset (mainaccounts);
 while (not eof(mainaccounts)) do
   begin
    readln(accounts, accnum);
    writeln(accnum:1)
   end;
end. {accountnumbers}
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
num : longint;

begin
assign(accounts, '/home/rd/rd013/programs/prog7/accounts.txt');
assign(mainaccounts, home/rd/rd013/programs/prog7/mainacocunts.txt');
reset (accounts);
rewrite(mainaccounts);
 while (not eof(accounts)) do
   begin
      readln(accounts, num);
      writeln(num);
     end;
   end; {while not eoln}
close(accounts);
close(mainaccounts);
end. {accountnumbers}

Use a longint to get the whole line.  Its a number you can use.  Unless you need to use chars.


This line

 rewrite(mainaccounts);

It seems you were doing this repeatedly.  Only needs to be done once.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

FosheeJoshAuthor Commented:
but I think I need to get a digit for each line because I need to verify if it is a correct nummber or not don't I? I mean how I'm I going to add up each number if it is all one number?
FosheeJoshAuthor Commented:
What I'm tring to do is get a single line over to another text file so then I can read the text file line by line for each digit to see if it adds up to the last line and if there is a blank then call it invalid? or do you think there is another approciate to it?
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
There's another way.  You don't need another file.

The largest eight digit number possible is 99999999

if num > 99999999 its a nine digit number

To add up all the digits well, lets assume you have a 2 digit number like 36

one :=  num mod 10; that'll give you the last digit which is 6

two := num div 10;  will give you the first digt which is 3

Think you can do it now?
Elvis1Commented:
i don't understand the way the controler should think
you gave as example
acc number 123456786
then you said
1+2+3+4+5+6+7+8+36
why +36 ? if a number appears to time do you have to take the square of it ???
for example
acc number 123456785
1+2+3+4+5+6+7+8+25
???

ELvis
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
1+2+3+4+5+6+7+8+36

should be

1+2+3+4+5+6+7+8=36

There are two checks here.  There should be nine numbers and the total of the nine numbers must equal a predetermined number, in this case 36.
Elvis1Commented:
Hi,

i taught you could proceed that way, i know it is a tourist way to do it, but i think i will do, my way will work if only "0" aren't allowed in the account number;

- first you create an array from 9 "spaces" of bytes (0-255, just what you need)
- then you create a procedure to set every space on "0"
- afterwards you begin to read digit by digit the account number;
- when this task is done you can begin to check wether it's an illegal or legal number (if it has enough digits or not too much); you can do this with a loop and a boolean value, something like

FUNCTION CheckLength:Boolean;
Var Temp, i:Byte;  \\you don't need more than a byte for those
Begin
Temp:=0;
FOR i:=1 TO 20 DO  \\let say 20 you will understand later
 IF ArrayName[i]<>0 THEN
  Temp:=Temp+1;
IF Temp<>9 THEN     \\because the account number
                      shouldn't have more than 9 digits
 CheckLength:=FALSE;
IF Temp=9 THEN
 CheckLength:=TRUE;
End;

at the end if the value is TRUE that means that there is just the right number of digits, if the value is FALSE the meaning is Illegal

- in your program you can compare IF CheckLength=TRUE THEN you can now count all the digits together and compare the sum this way
this function will check if the account number is Valid of Invalid

FUNCTION Valid_InValid:Boolean;
Var Sum:Byte;
Begin
 FOR i:=1 TO 9 DO          \\because you shouldn't use this func if there isn't the right number of digits
  Sum:=Sum+ArrayName[i];
 IF Sum=36 THEN
  Valid_InValid:=TRUE;     \\so Valid accoutn number
 IF Sum<>36 THEN
  Valid_InValid:=FALSe     \\so InValid account number
End;

- with all this you should get an idea from what you should do
End;

a snip from you BEGIN-END.-block should be something like this


SetUpArray;          \\procedure see step 1
ReadInFromTextFile   \\procedure see step 2
IF (CheckLength=TRUE) AND (Valid_InValid=TRUE) THEN


if you have some question about my way to proceed, just ask i would be glad to answer
Bye

Elvis
Elvis1Commented:
sorry it should be;
- first you creat an array from '20' spaces
sorry

bye
Elvis
Elvis1Commented:
don't look at this, i made a big big big mistake i will correct it later on
sorry
Elvis
Elvis1Commented:
what is meant by "6 is the rightmost' ???

Elvis
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
When you add up the numbers, you'll get a total.

if the number on the right of the total is 6 then you have a valid number.
Elvis1Commented:
on the right of the total sum huh ?
so for example;
sum = 46
sum = 56
sum = 36
=> valid
sum = 35
sum = 42
=> invalid

???
Elvis
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.Commented:
Yep
Elvis1Commented:
I have it,
you can split your program in 6 parts
to begin i give you the VAR-declaration

VAR
 AccNmbrCh:Array[1..20] Of Char;
 AccNmbrDigits:Array[1..20] Of Byte;
 Accounts:Text;
 Temp:Byte;

Now I give you the BEGIN-END. block

BEGIN
 Launch;
 ReadAccounts;
 ConvertAccNmbr;
 FOR Temp:=1 TO 20 DO
  IF AccNmbrDigits[Temp]<>40 THEN
   Write(AccNmbrDigits[Temp]);
 WriteLn;
 IF (CheckLength=TRUE) AND (CheckValid=TRUE) THEN
  WriteLn('Account Number Is Fully Legal And Valid')
 ELSE
  Write('Account Number Invalid Or Illegal');
 ReadLn;
END.

now the parts of the program
FIRST PART;
=>Procedure Launch
there in you do all you need for the Text-Files
stuff like assigning, reset, ...
and you setup the AccNmbrCh-array, every space with the "X" Character
with a loop

PART TWO;
=> Procedure ReadAccounts

PROCEDURE ReadAccounts;
Var j:Byte;
Begin
 j:=0;
 REPEAT
  j:=j+1;
  Read(Accounts, AccNmbrCh[j]);
 UNTIL (Eoln(Accounts)) OR (j=20);
End;

this procedure reads the acc # char by  char

PART TREE;
=>Procedure ConvertAccNmbr
this proced converts the characters into bytes(numbers)
and it stores the data in the AccNmbrDigits-array

PROCEDURE ConvertAccNmbr;
Var k:Byte;
Begin
FOR k:=1 TO 20 DO
 AccNmbrDigits[k]:=Ord(AccNmbrCh[k])-48;
 {look at the ascii table and find out what the "ord" func is all about
  if AccNmbrDigits=40 then it means that is isn't a number}
End;


PART FOUR;
=> Function CheckLength


FUNCTION CheckLength:Boolean;
Var Temp, i:Byte;
Begin
 Temp:=0;
 FOR i:=1 TO 20 DO
  IF AccNmbrDigits[i]<>40 THEN
   Temp:=Temp+1;
 IF Temp=9 THEN
  CheckLength:=TRUE
 ELSE
  CheckLength:=FALSE;
End;

PART FIVE
=> Func CheckValid
see the msg from DBURTON for explanations

FUNCTION CheckValid:Boolean;
Var Sum, i, LastDigit:Byte;
Begin
 Sum:=0;
 FOR i:=1 TO 9 DO
  IF AccNmbrDigits[i]<10 THEN
   Sum:=Sum+AccNmbrDigits[i];
 {Now aply the method from DBRUNTON}
 LastDigit:=Sum MOD 10;
 {that gives you the last digit}
 IF LastDigit=6 THEN
  CheckValid:=TRUE
 ELSE
  CheckValid:=FALSE;
End;

PART SIX
whatever you want to do now, the 2 checks are done
if the value of CheckLength is TRUE then it means the acc # is legal
if the value of CheckValid is TRUE then it means the acc # is Valid
i just put two writeln's that informs the user

now you have party the program you need
i didn't make it all for you
now you have to;
- write the Launch-Procedure
- use the algorythm in the way you need (i gave you the tools to do it)
- inform yourself about the things you don't understand

hope it helps
Bye

Elvis

mlmccCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

recommend - points dbrunton

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

mlmcc      
Pascal Page Editor
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.