Thread: "Variable Or Field Declared Void" And Other Errors

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    3

    Exclamation "Variable Or Field Declared Void" And Other Errors

    I'm creating a payroll program and here is my code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>  
    
    
    #define REPORTHEADING1 "     Employee              Pay      Hours     Gross     Tax       Net\n"
    #define REPORTHEADING2 "     Name                  Rate     Worked    Pay       Due       Pay\n"
    #define REPORTHEADING3 "     ===============       ====     ======    =====     ====      ====\n"
    #define REPORTHEADING4 "                           ====     ======    =====     ====      ====\n"
    #define REPORTLINEFORMAT1 "     %-20s%6.2f%11.2f%9.2f%9.2f%10.2f\n"
    #define REPORTLINEFORMAT2 "     Totals              %6.2f%11.2f%9.2f%9.2f%10.2f\n"
    #define REPORTLINEFORMAT3 "     Averages            %6.2f%11.2f%9.2f%9.2f%10.2f\n"
    
    
    
    
    #define COUNTLINEFORMAT "     Number of employees: %-10i\n\n"
    
    
    #define MAXREGHOURS 40
    #define OVERTIMERATE 1.5
    
    
    
    
    
    
    void PrintReportHeadings(FILE *reportFile); //printReportHeadings prototype
    
    
    void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate, 
            float *totGross,float *totdeferred,float *totFedtax,
            float *totStatetax,float *totSSItax,float *totNet,int *empCount); //InitializeAccumulators prototype
    
    
    void InputEmployeeData(char *firstName,char *lastName,
                float *hours,float *payrate,float *deferred); //InputEmployeeData prototype
    
    
    void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,
                float *gross); //CalculateGross prototype
    
    
    extern void CalculateTaxes(float gross,float deferred,float * fedtax,
                    float * statetax,float * ssitax); //CalculateTaxes prototype (external)
    
    
    float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
                    float deferred);
    
    
    void AddDetailToAccumulators(float regHours,float ovtHours,float payrate,
            float gross,float deferred,float fedtax,float statetax,
            float ssitax,float net,float *totRegHours,float *totOvtHours,
            float *totPayrate,float *totGross,float *totdeferred, 
            float *totFedtax,float *totStatetax,float *totSSItax,
            float *totNet);
    
    
    void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
                float payrate,float gross,float deferred,float fedtax,
                float statetax,float ssitax,float net);
    
    
    int main(void)
    {
        float ft,st,ssit;
        char firstName[10+1];
        char lastName[15+1];
        char fullName[25+1];
        float regHours, ovtHours, hours, payrate, deferred, gross, netpay;
        float totRegHours, totOvtHours, totPayrate, totGross,totdeferred, 
            totFedtax, totStatetax, totSSItax, totNet;
        int empcount;
        char answer;
        FILE * reportFile;
    
    
        reportFile = fopen("./report.txt","wt");
        if(reportFile = NULL) 
        {
            printf(" Report open request failed...\n");
            while(getchar() != '\n');
            exit(-90);// reqs <stdlib.h>
        }
    
    
        PrintReportHeadings(reportFile);
    
    
        InitializeAccumulators(&totRegHours,&totOvtHours,&totPayrate,&totGross,
            &totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet,
            &empcount);//set all accumulators to 0
    
    
        do
        {
        InputEmployeeData(firstName,lastName,&hours,&payrate,&deferred);
        CalculateGross(hours, payrate, &regHours, &ovtHours, &gross);
        CalculateTaxes(gross,deferred,&ft,&st,&ssit);
        netpay = CalculateNetPay(gross,ft,st,ssit,deferred);
        strcpy(fullName,lastName);
        strcat(fullName,", ");
        strcat(fullName,firstName);
    
    
        AddDetailToAccumulators(regHours,ovtHours,payrate,gross,deferred,ft,st,
            ssit,netpay,&totRegHours,&totOvtHours,&totPayrate,&totGross,
            &totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet);
    
    
        void PrintSummaryReport(reportFile,fullName,regHours,ovtHours,payrate,gross,deferred,
                ft,st,ssit,netpay)
    
    
        empcount++;
        printf(COUNTLINEFORMAT,empcount);
    
    
        printf("  do you have anymore? (Y/N): ");
        while(getchar() != '\n');
        answer = getchar();
        printf("\n");
    
    
        }
        while(answer != 'N' && answer != 'n');
    
    
        while (getchar()!= '\n');
        getchar();
        return 0;
    }
    
    
    void PrintReportHeadings(FILE *reportFile)
    {
            reportFile = fopen("./report.txt","wt");
            fprintf(reportFile,REPORTHEADING1);
            fprintf(reportFile,REPORTHEADING2);
            fprintf(reportFile,REPORTHEADING3);
    }
    
    
    
    
    void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate,
                    float *totGross,float *totdeferred,float *totFedtax,
                    float *totStatetax,float *totSSItax,float *totNet,int *empCount)
    {
            totRegHour, totOvtHours, totPayrate, totGross,totdeferred,
                    totFedtax, totStatetax, totSSItax, totNet, empCount = 0;
    }
    
    
    void InputEmployeeData(char *firstName,char *lastName,float *hours,
                float *payrate,float *deferred)
    {
        printf("  Enter employee first name : ");
        scanf("%s",firstName);
        printf("  Enter employee last name : ");
        scanf("%s",lastName);
        printf("  Enter %s's hours worked : ",firstName);
        scanf("%f",hours);
        printf("  Enter %s's pay rate : ",firstName);
        scanf("%f",payrate);
        printf("  Enter %s's amount deferred : ",firstName);
        scanf("%f",deferred);
    }
    
    
    void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,float *gross)
    {
    float overtimeHours(float hours);
    
    
        if(hours <= MAXREGHOURS)
        {
            *regHours = hours;
            *gross = hours * payrate;
        }
        else
        {
            *regHours = MAXREGHOURS;
            *ovtHours = overtimeHours(hours);
            *gross = payrate * MAXREGHOURS + OVERTIMERATE * payrate * (hours - MAXREGHOURS);
        }
    }
    
    
    float overtimeHours(float hours)
    {
        return hours - MAXREGHOURS;
    }
    float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
            float deferred)
    {
        return gross - (fedtax + statetax + ssitax + deferred);
    }
    void AddDetailtoAccumulators(float regHours,float ovtHours,float payrate,
                    float gross,float deferred,float fedtax,float statetax,
                    float ssitax,float netpay,float *totRegHours,float *totOvtHours,
                    float *totPayrate,float *totGross,float *totDeferred,
                    float *totFedtax,float *totStatetax,float *totSSItax,
                    float *totNet)
    {
        *totRegHours =+ regHours;
        *totOvtHours =+ ovtHours;
        *totPayrate =+ payrate;
        *totGross =+ gross;
        *totDeferred =+ deferred;
        *totFedtax =+ fedtax;
        *totStatetax =+ statetax;
        *totSSItax =+ ssitax;
        *totNet =+ netpay;
    }
    
    
    void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
                            float payrate,float gross,float deferred,float fedtax,
                            float statetax,float ssitax,float netpay)
    {
        reportFile = fopen("./report.txt","wt");
    
    
        fprintf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
            ssitax,netpay);
        fprintf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
    
    
        printf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
            ssitax,netpay);
        printf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
    }

    The errors I get are:
    variable or field PrintSummaryReport declared void


    in function voidPrintSummaryReport...
    cannot convert FILE to const car for argument to int printf(const char*...)
    which is for the following lines
    Code:
    printf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
            ssitax,netpay);
        printf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Well .... the OP of this thread has set the bar pretty low for effort trying to work out your problem, before resorting to asking for help.


    The first error (about "declared" void) is due to misplaced void keyword on line 112. A function declaration tells the compiler how a function can be called. A statement calling the function .... well ... calls it. The two are related (based on the declaration, the compiler checks if the call is valid) but not interchangeable.


    The error about being unable to convert FILE * to const char * (not car) is because fprintf() accepts a FILE * as the first argument. printf() - without the leading f - does not. reportFile is a FILE *.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Mar 2014
    Posts
    3
    Yes, I'm trying to get as much help as possible? Or did I do something not allowed I didn't not realize.

  5. #5
    Registered User
    Join Date
    Mar 2014
    Posts
    3
    Quote Originally Posted by grumpy View Post
    Well .... the OP of this thread has set the bar pretty low for effort trying to work out your problem, before resorting to asking for help.


    The first error (about "declared" void) is due to misplaced void keyword on line 112. A function declaration tells the compiler how a function can be called. A statement calling the function .... well ... calls it. The two are related (based on the declaration, the compiler checks if the call is valid) but not interchangeable.


    The error about being unable to convert FILE * to const char * (not car) is because fprintf() accepts a FILE * as the first argument. printf() - without the leading f - does not. reportFile is a FILE *.
    Thank you for the help, no matter how condescending it was.

  6. #6
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Floating point numbers are not recommended for dealing with currency.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Niki Robbers View Post
    Thank you for the help, no matter how condescending it was.
    Well, yeh. Given that software development is all about problem solving, I do tend to become condescending when responding to a post where the poster has obviously applied little or no effort to solve their problem, rather than offering to kiss their smelly feet. This is not one of the harder cases where the compiler has given cryptic or misleading error messages.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > Yes, I'm trying to get as much help as possible? Or did I do something not allowed I didn't not realize.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 39
    Last Post: 07-28-2013, 08:24 PM
  2. Glut two errors upon being compiled: "not declared terms"
    By drewtoby in forum C++ Programming
    Replies: 3
    Last Post: 05-23-2011, 02:19 PM
  3. "variable or field declared void"
    By Treborh in forum C++ Programming
    Replies: 13
    Last Post: 02-06-2010, 03:33 PM
  4. Replies: 1
    Last Post: 06-21-2005, 08:10 AM
  5. Replies: 5
    Last Post: 10-14-2004, 09:05 AM