![]() |
|
#1
|
|||
|
|||
Trouble with files and array linking to files.Hi guys, im back again...
just wondering if my code looks good so far, im having a bit of trouble understanding the way files work with arrays, but other than that im ok. If someone could look at the start of my program and tell me how it looks, that would be awesome. you guys helped me so much last time i needed it with functions and i ended up with a clean 100% on my assignment. here is the code so far. (remember is it in plain C) CPP / C++ / C Code:
my only problem is, when i take out the variables that dont have functions, and run it, the file that it writes to goes on infinitely... |
|
#2
|
|||
|
|||
Re: Trouble with files and array linking to files.umm, also i need a bit of help im calculating some numbers inside my functions.
it needs to be done like for example this is one i have started but cannot finish. Federal tax (FT) is deducted from gross pay. FT is calculated based on what a person would earn for a full year, assuming that the employee will make the current week's gross pay every week for a full 52 weeks. The rates are: 16% on the first $20,000 earned annually 23% on the next $20,000 earned annually 29% on the remainder earned annually my function looks like this so far CPP / C++ / C Code:
|
|
#3
|
||||
|
||||
Re: Trouble with files and array linking to files.Hi Blstretch,
Quote:
There are quite a few errors in your program: 1. Consider this function: CPP / C++ / C Code:
The error which comes up is : grosspay: Undeclared identifier So, the problem is grosspay is undeclared here. You have to initialize a variable grosspay inside the function, because the scope of the earlier grosspay is within the main function only. The, about the if else statements: Use braces. For example, : CPP / C++ / C Code:
CPP / C++ / C Code:
So, the updated function will be like this: CPP / C++ / C Code:
Similarly, modify the other function also. And what does your employees and payrates .dat files contain? Without knowing that, it will be difficult to guess what you are doing. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#4
|
||||
|
||||
Re: Trouble with files and array linking to files.Quote:
1. First multiply 52 to grosspay. (You already did!) 2. Check if grosspay is greater than 20000. If it is, then computer ft for 16%.Then subtract 20000 from grosspay, because you have computed for first 20000. (Can you understand this?) 3. Then, check using another if statement, whether grosspay is still greater than 20000. If it is, then add to ft, grosspay * 0.23 /52. Then subtract 20000 from grosspay again. 4. Then, add another 29% of remaining grosspay to ft. Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#5
|
||||||
|
||||||
Re: Trouble with files and array linking to files.Quote:
Quote:
Quote:
Quote:
I have no idea what I'm looking at nor for with no explanation of what the program is supposed to do, what it does wrong, where it's going wrong. It really needs comments. Quote:
Quote:
Think of it this way: Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#6
|
|||
|
|||
Re: Trouble with files and array linking to files.hehe first thanks alot...
second, sorry for the mess, i have been jumping from one language to another lately, my mind is a little jumbled. stupid html... ok, my files contain; payrates.dat 10 numbers, doubles, with each number on a new line. they ascend in wage as the go down the file. employees.dat contains 5 pieces of information, which looks like this: 0001:white:barry:5:34.5 first thing is employee number, second is last name, then first name, then payrate number(from file earlier), and finally the number of hours worked. and another thing is that i fixed a whole bunch of the errors myself while i as waiting for a reply...heh. soo. for now i would like to focus on the first function, and main. CPP / C++ / C Code:
um, also why is my scanf so bad? and the program is supposed to read the payrates.dat file, read the employees.dat file, calculate gross pay, net pay and tax and deductions, and write them into a thrid file, called payroll.dat. this must be done strictly in the program, and thats about it. so basicly i need to scan the payrates into an array, then scan the employee information, one employee at a time, calculate the nessary stuff for that employee, and write that info to the file. now, i noticed when i was looking through my code, to debug, that my function payroll doesnt get called in main, i have no idea how to call it, if it needs to be called or what. secondly, my file payroll.dat that i write the info to, seems to never end. the formatting is perfect, and the info gets written, aside from the zeros where other numbers should be, i dont know how to stop it from writing, and what i need to do to get the calculations to work.. oh, for the record, this is what the program looks like now that i debugged a little. CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: Trouble with files and array linking to files.um, when i try to run that program above....this is the error i get...i have no idea what it means
Phobos: /students/blstretc/test3-2>$ cc testy.c NFS write error on host castor_nw1_svc: 88. File: userid=5246, groupid=111 ld: 0711-711 ERROR: Input file testy.o is empty. The file is being ignored. |
|
#8
|
||||||
|
||||||
Re: Trouble with files and array linking to files.Quote:
Quote:
Quote:
scanf scanf / character scanf / string scanf / number scanf / epilog You are using fscanf() which is a little different. I may have read the code wrong initially, but that format string... Sheesh! But because the data is coming from a file, you have more control over the input and fewer problems should arise. Not guaranteed, but you don't have a 'user' on a keyboard trying to break your program. Quote:
Quote:
1: "i have no idea how to call it" -- why? Didn't you call other functions? What's so different about the payroll function that causes such a conundrum? 2: "if it needs to be called" -- does it do something useful? Is it important to the program to arrive at a correct answer/output? Sorry, but these questions don't make sense to me! Let's assume you do have to call it. 1) What information (data) is required for the function to work properly? 2) When in the program is that data guaranteed to be ready for the function? That's where you call it. Quote:
CPP / C++ / C Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#9
|
|||
|
|||
Re: Trouble with files and array linking to files.the problem is that i dont know how to call a function to put data into an array....
the funtion payroll above takes the data from the file, and scans it into an array. the array is supposed to be used later on to calculate grosspay, which is a different function. i just dont understand how to call the funtion from main, to set numbers into an array. |
|
#10
|
||||
|
||||
Re: Trouble with files and array linking to files.Quote:
CPP / C++ / C Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 22:26 |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 12:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The