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
324 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
  • 7
  • 6
  • 3
  • +1
18 Comments
 
LVL 47

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 47

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
 

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 47

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 47

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 47

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 47

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 100

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now