Posted: Thu Jan 08, 2004 11:01 pm Post subject: saving and laoding to files help
i did read teh tutorial but am still having this one error problem.... it says after teh program is done running , "Eof attempted on incompatible stream number 2"... it is supposed to write what is in the variables to a file, then put bye, but it dosen't put bye, it stops and this aerror occurs!. i don't know what teh problem is.. if u need the code tell me... thanks
Sponsor Sponsor
Dan
Posted: Thu Jan 08, 2004 11:05 pm Post subject: (No subject)
i think you are reading past the end of the file. you need to add an "exit when eof(stream)" to it to make it stop b4 it hits the end.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Boarder16
Posted: Thu Jan 08, 2004 11:20 pm Post subject: (No subject)
i already have that.. heres teh closeing code
cls
delay (1000)
open : stremout, "matt.txt", write
exit when eof (stremout)
write : stremout, account_information
put "Thank you for using Jones Investment Banking"
delay (2000)
close : stremout
Window.Close (w1)
and i've tried it like this
cls
delay (1000)
open : stremout, "matt.txt", write
write : stremout, account_information
exit when eof (stremout)
put "Thank you for using Jones Investment Banking"
delay (2000)
close : stremout
Window.Close (w1)
i also have the variable called properly at the top 2
Ashkan
Posted: Fri Jan 09, 2004 12:17 am Post subject: (No subject)
in case you wanna overwrite the previously written data just take off ,mod
code:
var stremout : int
var account_information : string := "blah"
var input : string
cls
delay (1000)
open : stremout, "matt.txt", put, get, mod
loop
exit when eof (stremout)
get : stremout, input
end loop
put : stremout, account_information
close : stremout
delay (2000)
put "Thank you for using Jones Investment Banking"
AsianSensation
Posted: Fri Jan 09, 2004 7:34 am Post subject: (No subject)
well, first of all, you are using write with a text file, which is a no no, because write is used with binary files. To just read and write normally with a textfile, use get instead.
DanShadow
Posted: Fri Jan 09, 2004 9:37 am Post subject: (No subject)
Seriously, just do it the easy way, save it under a String Variable.
code:
var datafile : int
var text, temp : string := ""
put "[1. Write to Disk]"
put "[2. Read from Disk]"
put "Choice: " ..
get text
if text = "1" then
put "Enter the filename: " ..
get temp : *
open : datafile, temp, put
put "Enter the text: " ..
get text : *
put : datafile, text
close : datafile
elsif text = "2" then
put "Enter the filename: " ..
get temp : *
open : datafile, temp, get
get : datafile, text
temp := text
close : datafile
text := temp
put "File Reads: " ..
put text
end if
put ""
put "Finished."
And im not sure why...but it only displays the first word in the datafile, but meh. Im just giving you a more general/easy idea of how to do it.
Boarder16
Posted: Sat Jan 10, 2004 2:56 pm Post subject: (No subject)
no its not like that.. here can be no user input.. it opens teh file hwen ran.... and clsoes it when done... but it load the info and saves the info 2
Boarder16
Posted: Sat Jan 10, 2004 3:30 pm Post subject: (No subject)
Heres all teh code so far... it won't run.. can you help even with all teh tutorials i read.. istill cn't get it to work.. it hink i was too confused and started mixing the get and read properties together....
code:
var action, deposit, withdrawl, start, account_number, invest, shares, cost, balance, shares1, shares2, shares3, shares4 : int
var stremout : int
var stremin : int
var w1 : int
balance := 10000
shares1 := 0
shares2 := 0
shares3 := 0
shares4 := 0
deposit := 0
proc banking_system
open : stremin, "matt.txt", get
loop
get : stremin, balance, shares1, shares2, shares3, shares4
exit when eof (stremin)
end loop
close : stremin
loop
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
get action
cls
if action = 1 then
put "Deposit"
put ""
put "How much would you like to deposit $" ..
get deposit
delay (1000)
cls
put "Your balance now is $", balance + deposit
balance := balance + deposit
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 2 then
put "Withdrawl"
put ""
put "How much would you like to withdraw? " ..
get withdrawl
if withdrawl > balance then
put "You exceeded your balance please try put in another amount"
else
balance := balance - withdrawl
put "Your Balance now is ", balance
end if
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 3 then
put "Balance"
put ""
put "Your balance is ", balance
delay (1500)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 4 then
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " Stocks Price Per Share"
put ""
put "1. NASDAQ $ 24"
put "2. GOLD $ 104"
put "3. NORTEL $ 9"
put "4. OIL $ 43"
put ""
put "Select a stock to invest in " ..
get invest
if invest = 1 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " NASDAQ $ 24"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 24) then
put ""
put "You do not have enough money"
delay (2000)
else
shares1 := shares1 + shares
balance := balance - (shares * 24)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 2 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " GOLD $ 104"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 104) then
put ""
put "You do not have enough money"
delay (2000)
else
shares2 := shares2 + shares
balance := balance - (shares * 104)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 3 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " NORTEL $ 9"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 9) then
put ""
put "You do not have enough money"
delay (2000)
else
shares3 := shares3 + shares
balance := balance - (shares * 9)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 4 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " OIL $ 43"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 43) then
put ""
put "You do not have enough money"
delay (2000)
else
shares4 := shares4 + shares
balance := balance - (shares * 43)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
else
end if
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 5 then
put "Stock Portfolio"
put ""
put "Your current stock portolio"
put ""
put " Stocks PPS Amount Own"
put "1. NASDAQ $ 24 ", shares1
put "2. GOLD $ 104 ", shares2
put "3. NORTEL $ 9 ", shares3
put "4. OIL $ 43 ", shares4
put ""
put " Total Money Invested"
put ""
put " ", shares1, " x $24 = $", (shares1 * 24)
put " ", shares2, " x $104 = $", (shares2 * 104)
put " ", shares3, " x $9 = $", (shares3 * 9)
put " ", shares4, " x $43 = $", (shares4 * 43)
put " "
put " 1. Sell"
put " 2. Exit"
put "Select an option " ..
get action
if action = 1 then
delay (2000)
cls
put "Stock Profile"
put ""
put " Stocks PPS Amount Own"
put "1. NASDAQ $ 24 ", shares1
put "2. GOLD $ 104 ", shares2
put "3. NORTEL $ 9 ", shares3
put "4. OIL $ 43 ", shares4
put ""
put "Select a stock to sell"
put " 1. NASDAQ"
put " 2. GOLD"
put " 3. NORTEL"
put " 4. OIL"
put " " ..
get action
if action = 1 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares1 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of NASDAQ for $", (shares * 24)
balance := balance + (shares * 24)
shares1 := shares1 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 2 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares2 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of GOLD for $", (shares * 104)
balance := balance + (shares * 104)
shares2 := shares2 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 3 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares3 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of NORTEL for $", (shares * 9)
balance := balance + (shares * 9)
shares3 := shares3 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 4 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares4 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of OIL for $", (shares * 43)
balance := balance + (shares * 43)
shares4 := shares4 - shares
put "Your balance is ", balance
delay (3000)
end if
end if
elsif action = 2 then
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
else
end if
elsif action = 6 then
cls
delay (1000)
open : stremout, "matt.txt", put
loop
put : stremout, balance, shares1, shares2, shares3, shares4
exit when eof (stremout)
end loop
put "Thank you for using Jones Investment Banking"
delay (2000)
close : stremout
Window.Close (w1)
exit
end if
end loop
end banking_system
banking_system
to test to see if it does save t oteh file oyu can change teh balance using teh program when it runs then re open it and see if the balance has changed.. but when you rer- un it you will ahev to take the default values for teh variables off..... liek balance : = 10000 and shares1 througgh 4 : = 0... thanks
Sponsor Sponsor
Boarder16
Posted: Sat Jan 10, 2004 3:31 pm Post subject: (No subject)
Heres all teh code so far... it won't run.. can you help even with all teh tutorials i read.. istill cn't get it to work.. it hink i was too confused and started mixing the get and read properties together....
code:
var action, deposit, withdrawl, start, account_number, invest, shares, cost, balance, shares1, shares2, shares3, shares4 : int
var stremout : int
var stremin : int
var w1 : int
balance := 10000
shares1 := 0
shares2 := 0
shares3 := 0
shares4 := 0
deposit := 0
proc banking_system
open : stremin, "matt.txt", get
loop
get : stremin, balance, shares1, shares2, shares3, shares4
exit when eof (stremin)
end loop
close : stremin
loop
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
get action
cls
if action = 1 then
put "Deposit"
put ""
put "How much would you like to deposit $" ..
get deposit
delay (1000)
cls
put "Your balance now is $", balance + deposit
balance := balance + deposit
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 2 then
put "Withdrawl"
put ""
put "How much would you like to withdraw? " ..
get withdrawl
if withdrawl > balance then
put "You exceeded your balance please try put in another amount"
else
balance := balance - withdrawl
put "Your Balance now is ", balance
end if
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 3 then
put "Balance"
put ""
put "Your balance is ", balance
delay (1500)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 4 then
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " Stocks Price Per Share"
put ""
put "1. NASDAQ $ 24"
put "2. GOLD $ 104"
put "3. NORTEL $ 9"
put "4. OIL $ 43"
put ""
put "Select a stock to invest in " ..
get invest
if invest = 1 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " NASDAQ $ 24"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 24) then
put ""
put "You do not have enough money"
delay (2000)
else
shares1 := shares1 + shares
balance := balance - (shares * 24)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 2 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " GOLD $ 104"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 104) then
put ""
put "You do not have enough money"
delay (2000)
else
shares2 := shares2 + shares
balance := balance - (shares * 104)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 3 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " NORTEL $ 9"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 9) then
put ""
put "You do not have enough money"
delay (2000)
else
shares3 := shares3 + shares
balance := balance - (shares * 9)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
elsif invest = 4 then
delay (1000)
cls
put "Investment Options"
put ""
put "Amount you may invest ", balance
put ""
put " OIL $ 43"
put ""
put "How many shares do you want to buy? " ..
get shares
delay (1000)
if balance < (shares * 43) then
put ""
put "You do not have enough money"
delay (2000)
else
shares4 := shares4 + shares
balance := balance - (shares * 43)
cls
put "Investment Options"
put ""
put "Your New Balance is ", balance
delay (2000)
end if
else
end if
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
put "Select an Operation " ..
elsif action = 5 then
put "Stock Portfolio"
put ""
put "Your current stock portolio"
put ""
put " Stocks PPS Amount Own"
put "1. NASDAQ $ 24 ", shares1
put "2. GOLD $ 104 ", shares2
put "3. NORTEL $ 9 ", shares3
put "4. OIL $ 43 ", shares4
put ""
put " Total Money Invested"
put ""
put " ", shares1, " x $24 = $", (shares1 * 24)
put " ", shares2, " x $104 = $", (shares2 * 104)
put " ", shares3, " x $9 = $", (shares3 * 9)
put " ", shares4, " x $43 = $", (shares4 * 43)
put " "
put " 1. Sell"
put " 2. Exit"
put "Select an option " ..
get action
if action = 1 then
delay (2000)
cls
put "Stock Profile"
put ""
put " Stocks PPS Amount Own"
put "1. NASDAQ $ 24 ", shares1
put "2. GOLD $ 104 ", shares2
put "3. NORTEL $ 9 ", shares3
put "4. OIL $ 43 ", shares4
put ""
put "Select a stock to sell"
put " 1. NASDAQ"
put " 2. GOLD"
put " 3. NORTEL"
put " 4. OIL"
put " " ..
get action
if action = 1 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares1 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of NASDAQ for $", (shares * 24)
balance := balance + (shares * 24)
shares1 := shares1 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 2 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares2 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of GOLD for $", (shares * 104)
balance := balance + (shares * 104)
shares2 := shares2 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 3 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares3 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of NORTEL for $", (shares * 9)
balance := balance + (shares * 9)
shares3 := shares3 - shares
put "Your balance is ", balance
delay (3000)
end if
elsif action = 4 then
delay (1000)
put ""
put "How many shares would you like to sell? " ..
get shares
if shares > shares4 then
put "You don't own that many shares"
else
put "You have sold ", shares, " shares of OIL for $", (shares * 43)
balance := balance + (shares * 43)
shares4 := shares4 - shares
put "Your balance is ", balance
delay (3000)
end if
end if
elsif action = 2 then
delay (2000)
cls
put ""
put "******************************************************"
put " ***Welcome to Jones Investment Banking*** "
put " 1. Make a Deposit"
put " 2. Make a Withdrawal"
put " 3. View Balance"
put " 4. Investment Options"
put " 5. Stock Portfolio"
put " 6. Exit Account"
put "******************************************************"
else
end if
elsif action = 6 then
cls
delay (1000)
open : stremout, "matt.txt", put
loop
put : stremout, balance, shares1, shares2, shares3, shares4
exit when eof (stremout)
end loop
put "Thank you for using Jones Investment Banking"
delay (2000)
close : stremout
Window.Close (w1)
exit
end if
end loop
end banking_system
banking_system
to test to see if it does save t oteh file oyu can change teh balance using teh program when it runs then re open it and see if the balance has changed.. but when you rer- un it you will ahev to take the default values for teh variables off..... liek balance : = 10000 and shares1 througgh 4 : = 0... thanks
Dan
Posted: Sat Jan 10, 2004 9:01 pm Post subject: (No subject)
i think you whont:
code:
loop
put : stremout, balance, shares1, shares2, shares3, shares4
exit when eof (stremout)
end loop
dont need to loop the output and you need spaces or it is all read i as one number next time.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Boarder16
Posted: Sat Jan 10, 2004 9:35 pm Post subject: (No subject)
i still have teh proble mwith teh get statement.. it says attempted to read past eof... could it be that i have no values on teh text file it is looking in..???
Dan
Posted: Sat Jan 10, 2004 10:05 pm Post subject: (No subject)
Boarder16 wrote:
i still have teh proble mwith teh get statement.. it says attempted to read past eof... could it be that i have no values on teh text file it is looking in..???
probly b/c when i ran your progmae with my chages and my own values in the text file it worked. try cahging your porgame like i side and remaking your txt file, numbers need to have a space or have to be on a difrent line to be read as difrent numbers.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Boarder16
Posted: Sat Jan 10, 2004 11:34 pm Post subject: (No subject)
is there anyway i can make i don't have to ask if it tehy first time using it type thing... u know what i mean.. if i did it ur way it would require me to change quite a bit.. and its very confusing lol..but i'll give it a shot..
Dan
Posted: Sat Jan 10, 2004 11:35 pm Post subject: (No subject)
? you just have to delte 3 lines and then add some spaces in another
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Boarder16
Posted: Sat Jan 10, 2004 11:43 pm Post subject: (No subject)
wait i think i understand it, but how would i get it so teh number i read are put back into the variables they once were in?
like so after i save like 4, and then open the 4 variables....how will it know which value is to which variable?