Help with bank program
Author |
Message |
Azzy

|
Posted: Wed Oct 19, 2005 9:29 pm Post subject: Help with bank program |
|
|
I saw avsrule's ATM program and decided to make my own bank program with intrest and deposits and stuff but I have a problem. It's probably some easy to fix stupid mistake I've made but oh well.
The problem is with the for-if statement at the end. Even though the pin number is correct, it still shows the pin is incorrect line. Please someone help me.
code: |
var strem : int
var temp : string
var pass:array 1..4 of string
var cont:string(1)
var pins : array 1 .. 10 of string
var balance : array 1 .. 10 of real
var names : array 1 .. 10 of string
var clientNum:int
open : strem, "bank.txt", get
for i: 1 .. 10
get : strem, names(i)
end for
for i: 1 .. 10
get : strem, pins(i)
end for
for i: 1 .. 10
get : strem, balance(i)
end for
loop
put "Please enter your pin number."
for x : 1..4
pass(x) := getchar
put "x"..
end for
temp := pass(1)+pass(2)+pass(3)+pass(4)
put ""
put "One moment please" ..
delay (500)
put "." ..
delay (500)
put "." ..
delay (500)
put "." ..
delay (500)
put "."
delay (500)
cls
for i : 1 .. 10
if temp = pins (i) then
clientNum := i
put "Hello ", names (clientNum), "! Your balance at this moment in time is $", balance (clientNum)
elsif i = 10 then
put "You input an incorrect pin code. Press any key to try again."
getch(cont)
exit
end if
end for
cls
end loop
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
bass_maniac
|
Posted: Wed Oct 19, 2005 10:02 pm Post subject: (No subject) |
|
|
I don't know the contents of your bank.txt file, but in the file do you have all the names first, then the pins and then the balances? Because this is the order you are getting them from the file. So if the file looks like
code: | "John Smith" "1234" "2449.87" | but you're reading all the names first you'll get
code: | names (1) := "John Smith"
names (2) := "1234"
names (3) := "2449.87" |
Also, are you sure you have quotes around the names in your file? If you don't, "John" and "Smith" will be considered two different names and that will throw off the rest of the values.
You can try those ideas first, but if you post your bank.txt file that'd make it easier to test your prog. |
|
|
|
|
 |
beard0

|
Posted: Wed Oct 19, 2005 10:13 pm Post subject: (No subject) |
|
|
The way you do it, if the first time through the loop, the first user isn't the one eneterd, then you tell them they are wrong and exit. Even if the user entered the pin for user #1, they are then compared to user number 2, who obviously isn't the same, it tells you you're wrong, and exits. You need to check all of them for accuracy inside the loop, set a boolean if you find a match, then check your boolean after the loop for failure. |
|
|
|
|
 |
MysticVegeta

|
Posted: Thu Oct 20, 2005 1:45 pm Post subject: (No subject) |
|
|
And also your code is not KISSED!
- Varible declaration
- getting 3 arrays at the same time
- delay(500)
put "."
delay(500)
put "."
use a for loop.
- set temp to 0 then you can "temp += array(x)"
- etc |
|
|
|
|
 |
|
|