you were doing something like this
1 2 3 4 5 6 7
|
menu()
addemployee() //1
menu()
addemployee() //2
menu()
addemployee() //3
...
|
the thing is that when a function ends, the program returns to its caller.
so going bottom-up, menu() ends, and goes back to addemployee(), which ends, writes a 3 to the file and goes back to menu().
that menu() ends and goes to addemployee(), which ends, writes a 2 to the file and goes back to menu().
the last `addemployee()' to end will write a 1 to your file, and thats what your program sees the next time you execute it.
instead, you may do something like
1 2 3 4 5
|
main()
while(true){
menu()
addemployee()
}
|
`menu()' calls `addemployee()', after both end the control goes back to main() which calls menu() agains because it's inside a loop.
> So the code that I made that includes `~employeenumber()' wipes out the file?
1 2
|
~employeenumber(){
ofstream outfile("Employee.txt", ios_base::out | ios_base::trunc);
|
yes, that's the meaning of the `trunc' option
> what are the options that I have to have the desired output?
I'll suggest you to get rid of `employeenumber' class. (you may use a statict member variable to keep track of the increasing id)
work with a container that will store all the employees and write it to a file just at the end of your program.