Jump to content

with menu

- - - - -

  • Please log in to reply
4 replies to this topic

#1
neelle26

neelle26

    Newbie

  • Members
  • Pip
  • 2 posts
I have problem in searching the information of employee's that i save already. and in the menu i don't know how to make condition

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define org_FILE "emprec.txt"
#define temp_FILE "temprecs.txt"
main()
{

char *eid[10],fname[50],add[50],dept,*desc[20],*des[20],*rpd[10],idsearch[10];
int post,val[5];


 char *day[]={"Monday","Tuesday","Wednesday","Thursday","Friday"};
 char start[5],end[5],ovstart[5],ovend[5];
/* double totalhr,comphr;               */
 int condition[1];
 int holiday;

 char * pchStart, * pchEnd, * pchOvStart, * pchOvEnd;
 float min2,min1,ovmin1,ovmin2;
 float hr,hr1,ovhr,ovhr1;
 float totalHR,ovtotalHR;
 float totalMIN,ovtotalMIN;
 float sumHR,ovsumHR;
 float sumMIN,ovsumMIN,TOTALHOURS;


FILE*fp;
fp=fopen(org_FILE,"r");


gotoxy(2,6);printf("_______________________________________________________________________________");
gotoxy(25,2);printf("WHA L. ANG TRABAHO CORPORATION");
gotoxy(26,3);printf("Magallanes St., Davao City");
gotoxy(27,5);printf("Payroll System");
gotoxy(2,7);printf("Enter Employee's ID to search :");
gotoxy(2,8);printf("-------------------------------------------------------------------------------");
fflush(stdin);
gotoxy(33,7);scanf("%s",idsearch);

gotoxy(2,9);printf("Employee's Name : ");
gotoxy(2,10);printf("Department      : ");
gotoxy(2,11);printf("Position        : ");
gotoxy(35,11);printf("Rate per Day  : ");
gotoxy(2,12);printf("-------------------------------------------------------------------------------");
gotoxy(2,13);printf("1)  Time in / Time out (DTR)");
gotoxy(2,14);printf("2)  Payroll Deduction");
gotoxy(2,15);printf("3)  Update");
gotoxy(15,17);printf("Choose a letter to access the next step [   ]");
gotoxy(2,18);printf("-------------------------------------------------------------------------------");
gotoxy(57,17);scanf("%i",&val);
{
for(int ctr=0;ctr<=4;ctr++)
        {
            //Daily hours code---------------------------
            /*  Start  */
            printf("\nEnter for %s start time: ",day[ctr]);
            scanf("%s",start);


            pchStart = strtok (start, ":");
            hr = atof(pchStart);

            while ( pchStart != NULL)
            {
                    printf ("%s ",pchStart);
                    min2=atof(pchStart);
                    pchStart = strtok (NULL, ":");
            }
        /*------------------------------------------*/


        /* End */
            printf("\nEnter for %s end time: ",day[ctr]);
            scanf("%s",end);

            pchEnd = strtok (end, ":");
            hr1 = atof(pchEnd);

            while ( pchEnd != NULL)
            {
                printf ("%s ",pchEnd);
                min1=atof(pchEnd);
                pchEnd = strtok (NULL, ":");
            }

        /*---------------------------------------------*/




        //Over time-------------------------------------
          printf("\nIs Overtime(0/1)");
         scanf("%d",&condition);

         if (condition[0]==0)
            {
             /*  Start  */
            printf("\nEnter for %s Overtime start time: ",day[ctr]);
         scanf("%s",ovstart);


            pchOvStart = strtok (ovstart, ":");
         ovhr = atof(pchOvStart);

             while ( pchOvStart != NULL)
            {
                 printf ("%s ",pchOvStart);
                    ovmin2=atof(pchOvStart);
                    pchOvStart = strtok (NULL, ":");
            }
      /*------------------------------------------*/


        /* End */
         printf("\nEnter for %s Overtime end time: ",day[ctr]);
            scanf("%s",ovend);

            pchOvEnd = strtok (ovend, ":");
         ovhr1 = atof(pchOvEnd);

             while ( pchOvEnd != NULL)
            {
             printf ("%s ",pchOvEnd);
                ovmin1=atof(pchOvEnd);
                pchOvEnd = strtok (NULL, ":");
            }

        /*---------------------------------------------*/
        //Overtime computation

          if (ovmin2 >0 )
            {
                ovhr=ovhr + 1;
            }

            ovtotalHR =(ovhr1-ovhr);
            ovsumHR = ovsumHR + ovtotalHR;
            ovtotalMIN= (ovmin2 + ovmin1)/60;
         ovsumMIN =ovsumMIN + (ovtotalMIN);
            }
      //end of Overtime code----------------------------



      //Holiday-----------------------------------------
        printf("Is holiday(0/1)");
      scanf("%d",&condition);

      if (condition[0]==0)
        {
          holiday=holiday + 1;
            printf("Holiday Approved");
      }
        //End of Holiday Code------------------------------

            //daily Computation
           totalHR =(hr1-hr)-1;
            sumHR = sumHR + totalHR;
            totalMIN= (min2 + min1)/60;
            sumMIN =sumMIN + (totalMIN);



            printf("\nDaily \n");
         printf("\nTotal Hours %.2f\n",totalHR);
            printf("\nTotal Hours(MIN) %.2f\n",totalMIN);

            printf("\n\n Overtime\n");
         printf("\nOvertime Total Hours %.2f\n",ovtotalHR);
            printf("\nTotal Overtime Hours(MIN) %.2f",ovtotalMIN);
   }  //end of loop dtr


    printf("\n\nTotal Hours Work %.2f", sumHR + sumMIN);
   printf("\nTotal Hours work overtime %.2f",ovsumHR + ovsumMIN);
    printf("\nTotal Holiday: %d",holiday);

    TOTALHOURS=sumHR + sumMIN + ovsumHR + ovsumMIN;
   printf("\nTotal Hours work with overtime %.2f",TOTALHOURS);
    getch();




}


}

Edited by Alexander, 10 December 2010 - 05:11 PM.
(code tags)


#2
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

Can you explain your problem a bit more. Like what information of employee you're searching: and what condition you want to impose. It would be best if you could filter out the part of the code which think is troublesome: and let us review that.

Thanks,

Munir

#3
Muted

Muted

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
As mnirahd stated: Please use [ CODE ] tags [ /CODE ] when posting your source code.

Thanks! :c-smile:
“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills

#4
neelle26

neelle26

    Newbie

  • Members
  • Pip
  • 2 posts
This code is for inputting and saving the employeer's information in the file. I have already save the file in emprec.txt... it work. "but the problem in my codes above #1. i cant search the file from the storage.and in the menu option i used if condition but its not working.there are 3 option to choose from. 1.) time in / time out, 2.) Payroll Deduction,and 3.) Update.i already have the codes for 1-3 option but i cant search the file.

can anyone help me in searching and for the menu option? "


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define org_FILE "emprec.txt"
#define temp_FILE "temprecs.txt"
#define p printf
#define i gets
#define s scanf
#define g gotoxy
main()
{

char *eid[10],fname[50],add[50],yn,dept,*desc[20],*des[20],*rpd[10];
int post,numero[20];
FILE*fp;
fp=fopen(org_FILE,"a");
clrscr();
gotoxy(25,2);printf("WHA L. ANG TRABAHO CORPORATION");
g(26,3);p("Magallanes St., Davao City");
g(27,5);p("EMployee's Information");
g(2,7);p("Enter Employee's ID :");
g(1,8);p("______________________________________________________________________");

g(2,9);p("Full Name           :");
g(2,10);p("Address             :");
g(2,11);p("Department[A/H/M/I] :");
g(2,12);p("POSITION[1/2/3/4]   :");
g(2,13);p("Rate Per Day        :");
g(45,10);p("Tel.No.           :");
g(45,11);p("Description       :");
g(45,12);p("Description       :");
g(1,14);p("_____________________________________________________________________");
g(25,15);p("Do you want to save [Y/N]?  ");
g(25,7);s("%s",&eid);
g(25,9);s("%s",&fname);
g(25,10);s("%s",&add);
g(70,10);s("%s",&numero);
balik:
g(25,11);s("%s",&dept);

if((dept=='a')||(dept=='A'))
{
*desc="ACCOUNTING";
}
if((dept=='h')||(dept=='H'))
{
*desc="Human Resorce";
}
if((dept=='m')||(dept=='M'))
{
*desc="Maintenance";
}
if((dept=='i')||(dept=='I'))
{
*desc="MIS Department";
}
g(65,11);p("%s",*desc);
while((dept!='a')&&(dept!='A')&&(dept!='h')&&(dept!='H')&&(dept!='m')&&(dept!='M')&&(dept!='i')&&(dept!='I'))
{
g(30,11);p("Wrong Input");
getch();
g(30,11);p("                ");
goto balik;}
again:
g(25,12);s("%i",&post);
if((post==1))
{
*des="Accountant";
*rpd="600.50";
g(65,12);p("Accountant");
g(25,13);p("650.50");
}
if((post==2))
{
*des="HR clerk";
*rpd="600.00";
g(65,12);p("HR Clerk");
g(25,13);p("500.00");
}
if((post==3))
{
*des="Janitor";
*rpd="250.00";
g(65,12);p("Janitor");
g(25,13);p("250.00");
}
if((post==4))
{
*des="Programmer";
*rpd="750.00";
g(65,12);p("Programmer");
g(25,13);p("750.00");
}
if((post==1)&&(post==2)&&(post==3)&&(post==4))
{
g(25,12);p("Wrong Input");
getch();
g(25,12);p("              ");
goto again;}
****:
g(55,15);s("%s",&yn);
if((yn=='y')||(yn=='Y'))
{
goto save;
}
 if((yn=='n')||(yn=='N'))
{
goto exit;}
while((yn!='y')&&(yn!='Y')&&(yn!='n')&&(yn!='N'))
{
g(55,15);p("wrong input");
getch();
g(55,15);p("                 ");
goto ****;}
save:
fprintf(fp,"%s/%s/%s/%s/%c/%i\n",eid,fname,add,numero,dept,post);
fclose(fp);
exit:
 clrscr();
 {
  fclose(fp);
gotoxy(30,10); printf("FIN!!!");

  }

  exit(0);
  return 0;
  }

Edited by Alexander, 10 December 2010 - 08:42 PM.
(code tags!)


#5
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

Can you try it in debugger: That should help you to get pointed at location which is troublesome. Also can you provide as a sample input?

Munir




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users