Thread: simple payroll need help here

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    8

    simple payroll need help here

    ok i've created the prototype program of a payroll system the problem is i don't know how it would write something into a file and load it again i've attached my code here since i dont know anything about the command and what to do on how to write in to a file

    Code:
    #include <stdio.h>
    #define p printf
    #define g gotoxy
    #define s scanf
    main()
    {
    int emp;
    char name[16],sel,choice;
    float OH,HpW,BR,OT,GP,OM,mpW,HR,OTM,ToT,HWW,ompW;
    
    
    	clrscr();
    
    
    
    
    	p("Enter Employee Code : ");s("%d",&emp);
    	p("\nEnter Employee Name : ");s("%s",&name);
    	p("\nEnter Total Overtime Hours : ");s("%f",&OH);
    	p("\nEnter Total Overtime Minutes : ");s("%f",&OM);
    	p("\nEnter Total Hours of Work/Week : ");s("%f",&HpW);
    	p("\nEnter Total minutes of Work/Week : ");s("%f",&mpW);
    	if(emp==1)
    	{BR=380;}
    	if(emp==2)
    	{BR=450;}
    	if(emp==3)
    	{BR=550;}
    	HR=BR/8;
    	OTM=OM/60;
    	ompW=mpW/60;
    	OT=HR*1.1*OH;
    	HWW=ompW+mpW;
    	ToT=OTM+OH;
    	GP=HR*HWW+ToT;
    	clrscr();
    	switch(emp)
    	{
    	 case 1:
    		{
    			p("\nEmployee Code: Waiter\n");
    			p("\nEmployee Name: %s\n",name);
    			p("\nGross Pay: %f\n",GP);
    			break;
    		}
    
    	 case 2:
    		{
    			p("\nEmployee Code: Cashier\n");
    			p("\nEmployee Name: %s\n",name);
    			p("\nGross Pay: %f\n",GP);
    			break;
    		}
    
    	 case 3:
    		{
    			p("\nEmployee Code: Manager\n");
    			p("\nEmployee Name: %s\n",name);
    			p("\nGross Pay: %f\n",GP);
    			break;
    		}
    	}
    	getch();
    	return 0;
    
    
    }
    Last edited by d4xyjen; 08-07-2009 at 09:49 AM. Reason: removed the gotoxy codes

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by d4xyjen View Post
    the problem is i don't know how it would write something into a file and load it again i've attached my code here since i dont know anything about the command and what to do on how to write in to a file
    What do you think this is supposed to mean to someone else?

    How To Ask Questions The Smart Way
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Quote Originally Posted by MK27 View Post
    What do you think this is supposed to mean to someone else?
    sorry about that sir is just want somebody to guide me or walk through it

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Another wayward program development.

    BEFORE you put in all these gotoxy code, and hard code the display, be sure you have the guts of your program working correctly, (very correctly).

    For instance, I can't run your program, because my console window only has 25 lines vertical. Your program needs 48+, which is *way* more than you need for a simple database text based, program. Also, it's a PITA to step through code that is full of gotoxy lines of code and delay(). WHY do you have line after line of delay for a database program???

    Usually fprintf() is used to write data to a file, and fgets() or fscanf() is used to retrieve that data from the file. Look at the file threads now active on the forum for examples of writing to, or reading from, a file. Both are shown.
    Last edited by Adak; 08-07-2009 at 09:11 AM.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    Are you sure you wrote that program or is the scooped off from some internet source (it looks like that) ?

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Quote Originally Posted by roaan View Post
    Are you sure you wrote that program or is the scooped off from some internet source (it looks like that) ?
    nope its not scooped from net



    Quote Originally Posted by Adak View Post
    Another wayward program development.

    BEFORE you put in all these gotoxy code, and hard code the display, be sure you have the guts of your program working correctly, (very correctly).

    For instance, I can't run your program, because my console window only has 25 lines vertical. Your program needs 48+, which is *way* more than you need for a simple database text based, program. Also, it's a PITA to step through code that is full of gotoxy lines of code and delay(). WHY do you have line after line of delay for a database program???

    Usually fprintf() is used to write data to a file, and fgets() or fscanf() is used to retrieve that data from the file. Look at the file threads now active on the forum for examples of writing to, or reading from, a file. Both are shown.

    ok sir thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM