Bank Machine Program: variable has no value
Author |
Message |
umaster
|
Posted: Thu Jun 07, 2007 7:20 pm Post subject: Bank Machine Program: variable has no value |
|
|
kk i need to figure this out by tonight or i am sooo done; i get 10% off my mark in computers. Anyways, when i run my program it says that my main variable: PINBalance has no value. Though when i look over the code it seems to have no reason for the variable to be empty. I am working with external files to save the back account PIN numbers and balance. Here is the code. Also this is whats in GaryPINBalance.txt:
2571
500000
7958
10000
1008
100800
any help would be greatly appreciated thx
code: |
var PINBalance : array 1..2,1..200 of string
var PINBalanceDraft:array 1..200 of string
var PINbalance : array 1..2,1..200 of real
var overdraft: array 1..2,1..200 of string
var balancetrue : array 1..200 of boolean
var enterpin : int
var answer : string
var enterpinstr : string
var counter : int := 0
var counter2 : int:=0
var position : int := 0
var counter5 :int:=1
var space:int
var stringarray : array 1..200 of string
var intlength : array 1..200 of int
var counter3 : int:=0
var column : int := 1
var action : array 1..5 of int
var account : array 1..2,1..200 of string
var account2 : array 1..200 of real
var account3 : array 1..200 of string
var error : int:=1
var number :int
var option : string
var check :int:=0
var opval : boolean := false
var filenumber : int
var filenumber2 : int
var PINtrue:boolean:=false
for o:1..200
balancetrue(o) := false
end for
account3(1) := "WD"
account3(2) := "DEP"
account3(3) := "BILL"
account3(4) := "ACC"
open : filenumber,"GaryPINBalance.txt",get
loop
counter := counter+1
counter2:=counter2+1
get : filenumber, PINBalance(column,counter)
if column = 1
then
column := 2
elsif column = 2
then
column :=1
end if
exit when eof (filenumber)
end loop
close : filenumber
open : filenumber2, "GaryPINBalanceDraft.txt", get
loop
counter3 := counter3 + 1
get : filenumber2, PINBalanceDraft(counter3)
exit when eof (filenumber2)
end loop
close : filenumber2
% function WD : real
% for i:1..200
% if balancetrue(i) = true and account(1,i) = "WD"
% then
% PINBalance(2,i):= realstr(strreal(PINBalance(2,i))-strreal(account(2,i)),0)
% end if
% end for
% result WD
% end WD
check := counter2 div 2
% procedure accountacc
% for i:1..counter5
% stringarray(i):= account(2,i)
% intlength(i):= length(stringarray(i))
% end for
% for i:1..200
% if space < intlength(i)
% then
% space := intlength(i)
% end if
% end for
% put "****************Account Activities****************"
% for i:1..2
% if PINbalance(2,i) > 0
% then
% Text.Colour (green)
% put "Opening Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% elsif PINbalance(2,i) <= 0
% then
% Text.Colour (red)
% put "Opening Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% end if
% end for
% for i:1..counter5
% put account3(i):30,"$",account2(i):space:2
% end for
% for i:1..200
% if PINbalance(2,i) > 0
% then
% Text.Colour (green)
% put "Closing Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% elsif PINbalance(2,i) <= 0
% then
% Text.Colour (red)
% put "Closing Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% end if
% end for
% end accountacc
loop
put "Please enter your PIN number:"
get enterpin
enterpinstr := intstr(enterpin)
number:=0
for i:1..check
if enterpinstr = PINBalance(1,i+number)
then
PINtrue:= true
balancetrue(i) := true
end if
number := number+1
end for
if PINtrue not= true and error not= 3
then
put "Sorry that PIN is invalid please enter it again"
error:= error+1
end if
if error = 3
then
put "Sorry that was your last try to enter a PIN"
end if
exit when PINtrue = true or error = 3
end loop
if error = 3
then
Error.Halt ("Invalid PIN number entered 3 times")
end if
for h:1..200
if balancetrue(h) = true
then
position := h
end if
end for
loop
put "There are four options you may choose from:"
put "- Withdraw (WD)"
put "- Deposit (DEP)"
put "- Pay a Bill (BILL)"
put "- Acount Activities (ACC)"
put "Please enter the abreviation of the option you want, located in the brackets"
put "(case sensetive, all capitals):"
loop
get option
for i:1..4
if option = account3(i)
then
opval := true
end if
end for
if opval = false
then
put "Sorry you have not entered a valid option please re enter the option you want"
end if
exit when opval = true
end loop
if option = "WD"
then
account (1,counter5) := "WD"
counter5 := counter5 +1
put "Your current balance is: ",PINBalance(2,position)
put "How Much Would You Like To Withdraw?"
get account (2,counter5)
elsif option = "DEP"
then
counter5 := counter5 +1
account (1,counter5) := "DEP"
put "Your current balance is: ",PINBalance(2,position)
put "How Much Would You Like To Deposit?"
get account (2,counter5)
elsif option = "BILL"
then
counter5 := counter5 +1
account (1,counter5) := "BILL"
put "Your current balance is: ",PINBalance(2,position)
put "How Much Is The Bill You Must Pay?"
get account (1,counter5)
elsif option = "ACC"
then
put "YAY"
%accountacc
end if
counter5 := counter5+1
put "Are there any more transactions?(Y/N)"
get answer
exit when answer = "N" or answer = "n"
end loop
| [/list] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
bapb10
|
Posted: Fri Jun 08, 2007 8:19 am Post subject: RE:Bank Machine Program: variable has no value |
|
|
you need to say wat each line does becuz i cant figure it out srry |
|
|
|
|
|
umaster
|
Posted: Fri Jun 08, 2007 12:20 pm Post subject: Re: Bank Machine Program: variable has no value |
|
|
kk sry about that here is the code with explained lines
Also it is not finished so there is no procedure for Deposit or Bill
code: |
var PINBalance : array 1..2,1..200 of string
var PINBalanceDraft:array 1..200 of string
var PINbalance : array 1..2,1..200 of real
var overdraft: array 1..2,1..200 of string
var balancetrue : array 1..200 of boolean
var enterpin : int
var answer : string
var enterpinstr : string
var counter : int := 0
var counter2 : int:=0
var position : int := 0
var counter5 :int:=1
var space:int
var stringarray : array 1..200 of string
var intlength : array 1..200 of int
var counter3 : int:=0
var column : int := 1
var action : array 1..5 of int
var account : array 1..2,1..200 of string
var account2 : array 1..200 of real
var account3 : array 1..200 of string
var error : int:=1
var number :int
var option : string
var check :int:=0
var opval : boolean := false
var filenumber : int
var filenumber2 : int
var PINtrue:boolean:=false
%**********Sets all values to false
for o:1..200
balancetrue(o) := false
end for
%*********
%*************************
% these are the values to chack with what the user entered what he wanted to do
account3(1) := "WD"
account3(2) := "DEP"
account3(3) := "BILL"
account3(4) := "ACC"
%*************************
%THIS RIGHT HERE IS WHERE THE PROGRAM GRABS THE VALUES FOR THE PIN NUMBERS AND BALANCES
open : filenumber,"GaryPINBalance.txt",get
loop
counter := counter+1
counter2:=counter2+1
get : filenumber, PINBalance(column,counter)
if column = 1
then
column := 2
elsif column = 2
then
column :=1
end if
exit when eof (filenumber)
end loop
close : filenumber
%*************
%This is for checking to see if an account is overdraft (can take out more than they have) or nooverdraft(obvious)
open : filenumber2, "GaryPINBalanceDraft.txt", get
loop
counter3 := counter3 + 1
get : filenumber2, PINBalanceDraft(counter3)
exit when eof (filenumber2)
end loop
close : filenumber2
%************
%**********Withdrawl function
% function WD : real
% for i:1..200
% if balancetrue(i) = true and account(1,i) = "WD"
% then
% PINBalance(2,i):= realstr(strreal(PINBalance(2,i))-strreal(account(2,i)),0)
% end if
% end for
% result WD
% end WD %**********
check := counter2 div 2
%***********This is for displaying all the account activities done by the user
% procedure accountacc
% for i:1..counter5
% stringarray(i):= account(2,i)
% intlength(i):= length(stringarray(i))
% end for
% for i:1..200
% if space < intlength(i)
% then
% space := intlength(i)
% end if
% end for
% put "****************Account Activities****************"
% for i:1..2
% if PINbalance(2,i) > 0
% then
% Text.Colour (green)
% put "Opening Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% elsif PINbalance(2,i) <= 0
% then
% Text.Colour (red)
% put "Opening Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% end if
% end for
% for i:1..counter5
% put account3(i):30,"$",account2(i):space:2
% end for
% for i:1..200
% if PINbalance(2,i) > 0
% then
% Text.Colour (green)
% put "Closing Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% elsif PINbalance(2,i) <= 0
% then
% Text.Colour (red)
% put "Closing Balance":30,"$",PINbalance(2,i):space:2
% Text.Colour (black)
% end if
% end for
% end accountacc
%**************
%*********This is where the user enters a PIN NUmber
loop
put "Please enter your PIN number:"
get enterpin
enterpinstr := intstr(enterpin)
number:=0
for i:1..check
if enterpinstr = PINBalance(1,i+number)
then
PINtrue:= true
balancetrue(i) := true
end if
number := number+1
end for
if PINtrue not= true and error not= 3
then
put "Sorry that PIN is invalid please enter it again"
error:= error+1
end if
if error = 3
then
put "Sorry that was your last try to enter a PIN"
end if
exit when PINtrue = true or error = 3
end loop
%**************
%***Halts the program
if error = 3
then
Error.Halt ("Invalid PIN number entered 3 times")
end if
%************
%******this is to see which balance belongs to the PIN entered
for h:1..200
if balancetrue(h) = true
then
position := h
end if
end for
%*************
%****This is where the user enters what account things he wants to do
loop
put "There are four options you may choose from:"
put "- Withdraw (WD)"
put "- Deposit (DEP)"
put "- Pay a Bill (BILL)"
put "- Acount Activities (ACC)"
put "Please enter the abreviation of the option you want, located in the brackets"
put "(case sensetive, all capitals):"
loop
get option
for i:1..4
if option = account3(i)
then
opval := true
end if
end for
if opval = false
then
put "Sorry you have not entered a valid option please re enter the option you want"
end if
exit when opval = true
end loop
if option = "WD"
then
account (1,counter5) := "WD"
counter5 := counter5 +1
put "Your current balance is: ",PINBalance(2,position)
put "How Much Would You Like To Withdraw?"
get account (2,counter5)
elsif option = "DEP"
then
counter5 := counter5 +1
account (1,counter5) := "DEP"
put "Your current balance is: ",PINBalance(2,position)
put "How Much Would You Like To Deposit?"
get account (2,counter5)
elsif option = "BILL"
then
counter5 := counter5 +1
account (1,counter5) := "BILL"
put "Your current balance is: ",PINBalance(2,position)
put "How Much Is The Bill You Must Pay?"
get account (1,counter5)
elsif option = "ACC"
then
put "YAY"
%accountacc
end if
counter5 := counter5+1
put "Are there any more transactions?(Y/N)"
get answer
exit when answer = "N" or answer = "n"
end loop
%*************
|
|
|
|
|
|
|
Saad
|
Posted: Fri Jun 08, 2007 2:53 pm Post subject: Re: Bank Machine Program: variable has no value |
|
|
It would be helpfull if you could tell what line the error is happening at or supply us with the txt file |
|
|
|
|
|
|
|