Thread: Some C Programming Help

  1. #1
    Registered User
    Join Date
    Jan 2010
    Location
    Spanish Town, Jamaica, Jamaica
    Posts
    33

    Exclamation Some C Programming Help

    Ok so i'm doing this program for school and i really need to get it done as quickly as possible we are suppose to write a program in "C" a payroll program to be exact its suppose to be something like this:

    Problem Statement - Jamrow Trading Co. Ltd has requested a payroll system to be designed in order to manage and maintain the moneys coming out of the company for the work done every 2 weeks by the employees of the company. The pay roll system must be easy to manage by the user and also calculations must be accurate to ensure that no mistakes are made. Also moneys owed for over-time to the workers must be calculated as well. The company has also stated that they want to be able to replicate hard copies of the payroll.


    Problem Definition - The program that will be created is a payroll system that will keep track of moneys coming in and out of Jamrow Trading Co Ltd. The program will carry out different function in order to achieve the necessary tasks that the user wishes to perform. The program will be created using 6 functions. The functions are stated below:

    1. Total Function – This function is designed to tally the moneys owed to the employees for a period of 2 weeks, for an 8 hour work day. The name that will be given to this function will be “total_func”.

    2. Tax Function – This function is designed to subtract the tax owed by the employees to the government. This function will be given the name “govtax_func”

    3. Over-Time Function – This function is designed to calculate the over time wages owed to specific workers if over time work is done. The function will be given the name “over_func”

    4. View Function – This function is designed to view all the members of the payroll and all the moneys owed to the employees for the duration of the 2 weeks that they have worked. The function will be given the name “view_func”

    5. Print Function – This function will be used to print the payroll for the two weeks on a hard copy, so that the company can have it in there record. The function will be given the name “print_func”

    6. Special Function – This function is used to add money granted by the employer to the employee. This function will be given the name “spec_func”

    7. Name Function – This function will be used to store the name of the employee in order to do the necessary calculations.. This function will be given the name “name-func”.

    Abstract: - A payroll system will be designed to keep track of the wages owed to the employees of Jamrow Trading Co. Ltd. The program will be developed using the programming language “C”. The program will calculate the total wages owed by the company to the employees on hourly bases for the duration of 2 weeks. The program will also be designed to subtract the taxes owed by the employees to the government. Added wages for overtime can also be calculated. Printing to hardcopy will also be available if the user wishes to have a hard copy.

    i don't even know if im on the right track because thats just how i thought i was gonna do it but i opened CODEBLOCKS and i never even know whats the first thing i should do. Can someone please help me with this.. it's a simple program and also i wanna do a flow chart.. thankzzz.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    how can you be studying programmming if you have not any idea where to start with your programs? what have you studied so far in your course?
    or are you doing some kind of tech course and the tutor has thrown you a cproject just as a curve ball to amuse himself and assumes you can just do it?
    Have you any programming experience, as a hobby say? Have you only just downloaded and opened code::blocks or have you used it before?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    The simpler or tougher the things will be, when u try to do it.......
    But before jumping in to the swimming pool every body thinks that, swimming is a tough job....
    Itz upon u what u wanna do u wanna stare pool, or wanna jump

    Happy C/C++ Programming for jumpers.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Location
    Spanish Town, Jamaica, Jamaica
    Posts
    33
    im actually doing this in school but im lost in da class...

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Are you saying that you can't write and compile a "Hello World" program in Code::Blocks at all?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Jan 2010
    Location
    Spanish Town, Jamaica, Jamaica
    Posts
    33

    Exclamation

    Quote Originally Posted by iMalc View Post
    Are you saying that you can't write and compile a "Hello World" program in Code::Blocks at all?
    lolz im not that bad ok i can do a lil sumn sumn...

  7. #7
    Registered User
    Join Date
    Jan 2010
    Location
    Spanish Town, Jamaica, Jamaica
    Posts
    33
    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int add_emp()
    {
        FILE *fp;
        fp=fopen("RP_PR.txt","a+");
    
          char emp_name;//Variable to store Employees name
          int emp_s_hrs;//Variable to store standard work hrs
          int am_phr;//Variable to store ammount per hour
          float tax = 17.5;
          float total_payout_b4_tax; //Variable to store total owed before tax
          float total_payout_after_tax;
          int per_val = 100;
          int over_time;
    
    
                printf("\n\t\t\t\tNew Employee Screen");// New Employee Screen
    
                printf("\n\nPlease Enter Employee Name: ");// Asking User to enter Employee Name
                scanf("%s",&emp_name);// collecting student name from user
    
                printf("\nPlease Enter Standard Hourly Work Week: ");// Asking User to enter Standard Hourly Work Week
                scanf("%d",&emp_s_hrs);// Storing Standar Employee Work Week
    
                printf("\nPlease Enter Amount Per Hour: ");// Asking User to amount per hour
                scanf("%d",&am_phr);// Storing the amount per hour
    
                //printf("\nPlease Enter Tax Percentage Dedeuction:");
                //scanf("%d",&tax);
    
                    {
    
    
    
                            total_payout_b4_tax = emp_s_hrs * am_phr;
                            printf("\nAmount Before Tax Is :%.2f \n", total_payout_b4_tax);
    
                            total_payout_after_tax = (tax / per_val) * total_payout_b4_tax;
                            printf("\nAmount After Tax Is:%.2f \n", total_payout_after_tax);
                    }
    
    
                 fprintf(fp,"\nPayroll Details For: %s",emp_name);
                 fprintf(fp," \nAmount Befor Tax: %f", total_payout_b4_tax);
                 fprintf(fp,"\nAmount After Tax: %f", total_payout_after_tax);
    
                 fprintf(fp,"\n----------------------------------------------------");//separator for each payout
    fclose(fp);
    printf("\nData Hase Been Successfully Copied");
    
    }
    
    int view_payroll()//Function to Veiw Report Card
    {
          char emp_name[500];//Variable to store Employees name
          int emp_s_hrs[5];//Variable to store standard work hrs
          int am_phr[10];//Variable to store ammount per hour
          int tax;
          float total_payout_b4_tax = 0; //Variable to store total owed before tax
          float total_payout_after_tax = 0;
    
                FILE *fp;
                fp=fopen("RP_PR.txt","r");
    
                if(fp == NULL)
                {
                    printf("Error Report: File Access Error (ERROR CODE 312)\n");
                    return 1;
                }
                else {
                    printf("File Access Successfully.Payroll Sheet:\n\n");
                    while(fgets(emp_name,500,fp)!=NULL)
                    {
                        printf("%s",emp_name);
                    }
                    }
                fclose(fp);
    
    }
    
    int menu_main()
    {
        int selection;
        printf("\t\t****Welcome To The Right Price Payroll Center****\n\n\n\n\n\n");
        printf("\t\t\t\tBy Darien Ruddock\n\n\n");
    
        printf("To Add A New Employee Press One (1)\n\n");
        printf("To View Payroll Payouts press Two (2)\n\n");
        printf("To Edit Employee Details Press Three (3)\n\n");
        printf("To Exit Press Four (4)\n\n\n");
        scanf("%d", &selection);
    
            switch(selection)
               {
                             case 1: add_emp();
                             break;
                             break;
                             case 2: view_payroll();
                             break;
                             default: printf("Please Select A Choice;...");
               }
    
        return 0;
    }
    
    void main()
    {
    
    char choice;
           {
           menu_main();
           printf("\nReturn To The Main Menu? y/n: \n");
           scanf("%c",&choice);
           }
    
           while(choice == 'y');
             if(choice =='n')
            {exit(0);}
    
    }
    Im here but the program chrases in WIN XP

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You have to find the cause of the crash then. One big clue will be: when does it crash?
    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

  9. #9
    Registered User
    Join Date
    Jan 2010
    Location
    Spanish Town, Jamaica, Jamaica
    Posts
    33
    ok i fixed the crash.. anyway im at calculating over time and it just wont output a value seeing that im a noob can someone please help..

    Code:
    int emp_add()
    {
        FILE *fp;
        fp=fopen("RP_PR.txt","a+");
    
         char emp_name_f[15];
         char emp_name_l[15];
         int emp_s_hrs;
         int am_phr;
         float total_payout_b4_tax;
         float total_payout_after_tax;
         float tax = 17.5;
         float o_time;
         int o_val = 2;
         int per_val = 100;
    
         printf("\n\t\t\t\tEmployee Maintenance Screen\n\n");// New Employee Screen
         printf("\n----------------------------------------------------\n");
         printf("\nPlease Enter Employee First Name: ");// Asking User to enter Employee Name
         scanf("%s",&emp_name_f);// collecting student name from user
         printf("\n----------------------------------------------------\n");
         printf("\nPlease Enter Employee's Last Name: ");
         scanf("%s",&emp_name_l);
         printf("\n----------------------------------------------------\n");
         printf("\nPlease Enter Standard Hourly Work Week:");// Asking User to enter Standard Hourly Work Week
         scanf("%d",&emp_s_hrs);// Storing Standar Employee Work Week
         printf("\n----------------------------------------------------\n");
         printf("\nPlease Enter Amount Per Hour:$");// Asking User to amount per hour
         scanf("%d",&am_phr);// Storing the amount per hour
         printf("\n----------------------------------------------------\n");
         printf("\nPlease Enter Over Time Hours (Enter 0 If None):");
         scanf("%.2f",&o_time);
    
         system("CLS");
    
    
                    {
                            printf("\n----------------------------------------------------\n\n");
    
                            printf("Payroll Details For: %s %s\n", emp_name_f, emp_name_l);
    
                            printf("\n----------------------------------------------------\n\n");
    
    
                            total_payout_b4_tax = emp_s_hrs * am_phr;
                            printf("\nAmount Before Tax Is :%.2f \n", total_payout_b4_tax);
    
                            total_payout_after_tax = total_payout_b4_tax - (tax / per_val * total_payout_b4_tax) ;
                            printf("\nAmount After Tax Is:%.2f \n", total_payout_after_tax);
    
                            printf("\nTax Percentage: %.2f\n", tax);
    
                            o_time = o_val+total_payout_after_tax;
                            printf("\nOver Time Payout Is:\n", o_time);
                    }
    
    
                fprintf(fp,"\nPayroll Report Generated On:"__DATE__);
                fprintf(fp,"\n----------------------------------------------------\n");
                fprintf(fp,"\nPayroll Details For: %s %s\n",emp_name_f, emp_name_l);
                fprintf(fp," \nAmount Befor Tax: %.2f\n", total_payout_b4_tax);
                fprintf(fp,"\nAmount After Tax: %.2f\n", total_payout_after_tax);
                fprintf(fp,"\nTax Percentage: %.2f\n", tax);
                fprintf(fp,"\n\Over Time:\n", o_time);
    
                fprintf(fp,"\n----------------------------------------------------");//separator for each payout
    fclose(fp);
    printf("\n----------------------------------------------------\n");
    printf("Data Hase Been Successfully Copied\n");
    printf("----------------------------------------------------\n\n");
    
    getchar();

Popular pages Recent additions subscribe to a feed