Salary Finder (Regarding records)
Author |
Message |
xXInsanityXx
|
Posted: Sun Nov 27, 2005 8:32 am Post subject: Salary Finder (Regarding records) |
|
|
Not really a salary finder but thats what i will call this program
K, i work at McDonalds, and i want to keep an account of my salary, etc.I decided to create a mini database in turing, and am using records
but for some reason my code is not working, im totaly new to records so please bare along...
code: |
type salaryInfo :
record
numHours : real
payPerHour : real
breakMinutes : real
totalSalary : real
salaryWithTax : real
salaryRecieved : real
salaryCredit : real
salaryToDate : real
end record
var info: salaryInfo
loop
get info
end loop
|
i have even tried arrays
code: |
var info: array 1..100 of salaryInfo
for x: 1..100
get salaryInfo (x)
end for |
so could anyone explain why this code is not working? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 9:35 am Post subject: (No subject) |
|
|
You can't just get or put an entire record. It would be nice if you could, but you can't. (Actually, you can, but then you're using read/write, and you are not working with the user/the output window: you're working with files. Still, you will likely want to look into that for your program. Check the Turing Walkthrough.)
You have to manually get each field of your record.
code: |
type salaryInfo :
record
numHours : real
payPerHour : real
breakMinutes : real
totalSalary : real
salaryWithTax : real
salaryRecieved : real
salaryCredit : real
salaryToDate : real
end record
var info: salaryInfo
get info.numHours
get info.payPerHour
% ...
|
And I don't know why you had your get in a loop. |
|
|
|
|
|
xXInsanityXx
|
Posted: Sun Nov 27, 2005 10:48 am Post subject: (No subject) |
|
|
Oh, i probably misread, i read a tutorial on records (AsianSensations i think) and it had the record type as an array, so i tried it but i fared no luck... i was wondering if i could get numHours, payPerHour, breakMinutes and write it into a txt document? |
|
|
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 11:41 am Post subject: (No subject) |
|
|
xXInsanityXx wrote: Oh, i probably misread, i read a tutorial on records (AsianSensations i think) and it had the record type as an array, so i tried it but i fared no luck...
I'm not sure I understand what you're saying. You did it correctly, in your first post. You just didn't get it correctly. Like I said, you have to get and put each field of the record manually. You can't get and put an entire record at once. (A field of a record is, for example, numHours or salaryWithTax.)
xXInsanityXx wrote: i was wondering if i could get numHours, payPerHour, breakMinutes and write it into a txt document?
Sure. There are two ways to do this. First, use put. But like I said, you have to put each field manually.
code: |
var fileStream : int
open : fileStream, "database.txt", put
put : fileStream, info.numHours
put : fileStream, info.payPerHour
put : fileStream, info.breakMinutes
close : fileStream
|
Alternatively, you could use random-access, via write, which allows you to write a whole record at once (and you can read a whole record at once as well!). Note that you're data file will not be understandable.
code: |
var fileStream : int
open : fileStream, "database.txt", write
write : fileStream, info
close : fileStream
|
|
|
|
|
|
|
MysticVegeta
|
Posted: Sun Nov 27, 2005 11:46 am Post subject: Re: Salary Finder (Regarding records) |
|
|
xXInsanityXx wrote: Not really a salary finder but thats what i will call this program
K, i work at McDonalds, and i want to keep an account of my salary, etc.I decided to create a mini database in turing, and am using records
but for some reason my code is not working, im totaly new to records so please bare along...
code: |
type salaryInfo :
record
numHours : real
payPerHour : real
breakMinutes : real
totalSalary : real
salaryWithTax : real
salaryRecieved : real
salaryCredit : real
salaryToDate : real
end record
var info: salaryInfo
loop
get info
end loop
|
i have even tried arrays
code: |
var info: array 1..100 of salaryInfo
for x: 1..100
get salaryInfo (x)
end for |
so could anyone explain why this code is not working?
I am confused, why do you need records to do it? How about making a program that takes this stuff in using variables and saves it in a text file in a nice clean table... I dont see a use for records but I might be wrong because I dont know what you have planned. |
|
|
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 1:10 pm Post subject: Re: Salary Finder (Regarding records) |
|
|
MysticVegeta wrote: I am confused, why do you need records to do it? How about making a program that takes this stuff in using variables and saves it in a text file in a nice clean table... I dont see a use for records but I might be wrong because I dont know what you have planned.
Records aren't a bad idea. Especially since they'll allow him to read/write things to files very easily. |
|
|
|
|
|
MysticVegeta
|
Posted: Sun Nov 27, 2005 2:03 pm Post subject: (No subject) |
|
|
Me thinks using varibles should be able to do that, if you put them in a loop that is. |
|
|
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 2:08 pm Post subject: (No subject) |
|
|
MysticVegeta wrote: Me thinks using varibles should be able to do that, if you put them in a loop that is.
Absolutely. But which is neater? Do you want to package all the data regarding his pay into a single variable unit? Or would you prefer to leave it floating around, like ... like the potato chips that Homer brought about the spacecraft.
Sorry, I couldn't think of a better simile. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Sun Nov 27, 2005 2:44 pm Post subject: (No subject) |
|
|
You want barbeque chips, and your friend wants ranch chips. You can either have have a big barrel full of assorted chips and sort them out, or you can have two sealed bags that you know only contain either barbeque or ranch chips. |
|
|
|
|
|
|
|