Solved

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

Posted on 2003-11-24
18
342 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:FosheeJosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +1
18 Comments
 
LVL 49

Expert Comment

by:dbrunton
ID: 9815847
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.
0
 

Author Comment

by:FosheeJosh
ID: 9815859
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}
0
 
LVL 49

Accepted Solution

by:
dbrunton earned 125 total points
ID: 9815906
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.

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:FosheeJosh
ID: 9815952
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?
0
 

Author Comment

by:FosheeJosh
ID: 9815972
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?
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 9816049
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?
0
 

Expert Comment

by:Elvis1
ID: 9876484
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
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 9880379
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.
0
 

Expert Comment

by:Elvis1
ID: 9885456
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
0
 

Expert Comment

by:Elvis1
ID: 9887690
sorry it should be;
- first you creat an array from '20' spaces
sorry

bye
Elvis
0
 

Expert Comment

by:Elvis1
ID: 9888103
don't look at this, i made a big big big mistake i will correct it later on
sorry
Elvis
0
 

Expert Comment

by:Elvis1
ID: 9888400
what is meant by "6 is the rightmost' ???

Elvis
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 9889010
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.
0
 

Expert Comment

by:Elvis1
ID: 9889024
on the right of the total sum huh ?
so for example;
sum = 46
sum = 56
sum = 36
=> valid
sum = 35
sum = 42
=> invalid

???
Elvis
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 9889120
Yep
0
 

Expert Comment

by:Elvis1
ID: 9889147
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

0
 
LVL 101

Expert Comment

by:mlmcc
ID: 10189617
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question