Thread: Need simple loop and error checking for major assignment

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    36

    Need simple loop and error checking for major assignment

    ye i posted here b4 and cant find my older posts and i guess its because the SERVER KEEPS DELETING ME AND MY PROFILE AND MY EMAIL. anyways lol right now i need the above i need a simple loop that when the user inputs a number instead of a name it prompts back for the name prob that could be the error checker too this is my program its a payroll system

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    
    
    int add_hours(int *hours);
    int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
    int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours);
    int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3);
    
    int main(int argc,char **argv)
    {
         printf("\t//*****************St.Jago High School******************\\ \n\n");
        printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
          printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
    
        char fname[50];
        char lname[50];
    
    
        printf("Enter the employee's First Name:\n");
      scanf(" %[^\n0-9]s ",fname);
    
      printf("Enter the employee's Last Name:\n");
      scanf(" %[^\n0-9]s ",lname);
    
      getchar();
    
    
    
    int hours=0;
    int over_time=0;
    int normal_pay=0;
    int bonus=0;
    int salary_deduct=0;
    int education_tax=0;
    int NHT_tax=0;
    int NIS_tax=0;
    int medical_dental=0;
    int netpay=0;
    int netpay1=0;
    int netpay2=0;
    int netpay3=0;
    
    add_hours(&hours);
    salaryselect(&hours,&salary_deduct,&normal_pay,&over_time,&bonus);
    tax(&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&hours);
    net_pay(&hours,&over_time,&normal_pay,&bonus,&salary_deduct,&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&netpay,&netpay1,&netpay2,&netpay3);
    }
    
    int add_hours(int *hours)
    {
        int mo, tu, we, th, fr;
    printf("Enter daily hours for Monday:\n");
    scanf("%d",&mo);
    
    printf("Enter daily hours for Tuesday:\n");
    scanf("%d",&tu);
    
    printf("Enter daily hours for Wednesday:\n");
    scanf("%d",&we);
    
    printf("Enter daily hours for Thursday:\n");
    scanf("%d",&th);
    
    printf("Enter daily hours for Friday:\n");
    scanf("%d",&fr);
    *hours=mo+tu+we+th+fr;
    printf("\nThe weekly hours are:%d\n",*hours);
    
    printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    
    }
    
    int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
    {
    
        *normal_pay=*hours*20;
        *over_time=(*hours-60)*40+*normal_pay;
        *salary_deduct=*hours*20-*hours*10;
        *bonus=*over_time+3000;
    
        if(*hours<=40)
        printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
        else if(*hours<=60)
        printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
        else if(*hours<=70)
        printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
        else
        printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
    
        printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
        printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    
    }
    
    int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours)
    {
        *education_tax=*hours*20*.06;
        printf("Education tax of %6:$-%d\n",*education_tax);
        *NHT_tax=*hours*20*.1;
        printf("NHT tax of %10:$-%d\n",*NHT_tax);
        *NIS_tax=*hours*20*.05;
        printf("NIS tax of %5:$-%d\n",*NIS_tax);
        *medical_dental=*hours*20*.05;
        printf("Medical/dental of %5:$-%d\n",*medical_dental);
    }
    
    int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3)
    {
    
    
    
        *netpay=*salary_deduct-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
        *netpay1=*normal_pay-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
        *netpay2=*over_time-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
        *netpay3=*bonus-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
    
        if(*hours<=40)
        printf("The net pay is:$%d\n",*netpay);
        else if(*hours<=60)
        printf("The net pay is:$%d\n",*netpay1);
        else if(*hours<=70)
        printf("The net pay is:$%d\n",*netpay2);
        else
        printf("The net pay is:$%d\n",*netpay3);
    
    printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by zangetsu View Post
    ye i posted here b4 and cant find my older posts and i guess its because the SERVER KEEPS DELETING ME AND MY PROFILE AND MY EMAIL.
    Yeah, that's a problem, see here for a partial explanation:
    Whoa, what happened? (Again)

    i need a simple loop that when the user inputs a number instead of a name it prompts back for the name prob that could be the error checker too
    How much of the code you posted is relevant to this? Not much, perhaps. Actually, I don't see any attempt to write such a loop. So this code is, in that sense, completely irrelevant.

    Forget about your main program for now and try to write a loop which does what you are asking for. If/when it doesn't work properly, you can post that and ask why your loop doesn't work and how you can fix it. When it all works, it will be easy to incorporate it into the main program.

    If you can't even get that far, focus on what specifically it is that is preventing you from doing so.
    Last edited by MK27; 02-07-2010 at 12:21 PM.
    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
    Feb 2010
    Posts
    36
    ye..hres the thing i dont know crap bout programming so u cannot tell mi that and expect me to do anything i am on a serious deadline here so if u can at least tell me some instructions that i could tr or whatever that would be appreciated

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by zangetsu View Post
    ye..hres the thing i dont know crap bout programming so u cannot tell mi that and expect me to do anything i am on a serious deadline here so if u can at least tell me some instructions that i could tr or whatever that would be appreciated
    He did give you instructions. No one is going to write the code for you.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    If you can't think of something to at least try based on what we've given you, I highly recommend you drop the class because your mind is not suited to programming.

    If you can think of something, try it. If it doesn't work the way you want, post your code and someone will help you with it.
    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

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Quote Originally Posted by Epy View Post
    He did give you instructions. No one is going to write the code for you.
    I clearly dont remember BEGGING anyone to write jack ........ for me all i asked is that you show me of a thread or a tutorial that you know of that might help me you need to seriously stop treating newbies as if they were street junkies if your not gonna show me a thread or help me in any other way then dont say anything at all

Popular pages Recent additions subscribe to a feed