Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:39:29+00:00 2026-06-09T04:39:29+00:00

So below is the main portion of my code. There are a few external

  • 0

So below is the main portion of my code. There are a few external files that I am working with. In function 3.6, I am having trouble taking the average of my (in this case) total payrate(pr) and my total employees(empCount). Is there something that I am missing here? When I compile it, I get an error that says invalid operands. When I fix those, my output is 0. I am very new with programming, so bear with me while I try to answer any questions. The function I am having trouble with is the second to last function in the code(3.6 AddDetailToAccumulator). Thanks much.

#include <stdio.h>
#include <stdlib.h>
#include "EmployeeRecord.h"
#include "CalcTaxes.o"
#define ADDR(var) &var
#define REPORTCOLUMNHEADINGS1 "Employee           Pay    Reg Hrs  Gross    Fed     SSI     Net\n"
#define REPORTCOLUMNHEADINGS2 "Name               Rate   OVT Hrs  Pay      State   Defr    Pay\n"
#define BARS                  "========           =====  =======  =======  ======  ======  =======\n\n"  
#define REPORTCOLUMN1         "%s, %s\t%8.2f%8.2f%10.2f%8.2f%8.2f%9.2f\n"
#define REPORTCOLUMN2         "%32.2f%18.2f%8.2f\n\n"

void PrintReportHeadings(FILE * ReportFile); //3.1
void InputEmployeeData(int count,char * lastname,char * firstname,float * hours,float * payrate,float * defr); //3.3
float CalculateGross(float hours, float payrate, float reghours, float ovthours); //3.4 CalculateGross
extern void CalculateTaxes(float gross, float defr, float *ft, float *st, float *ssit); //3.5 CalculateTaxes
void AddDetailToAccumulator(int count,int *empCount,float *pr,float *payrate,float *reg,float *reghours,float *ovt,float *ovthours,float *gp,
                                float *gross,float *fedt,float *ft,float *stt,float *st,float *sst,float *ssit,float *def,
                                float *defr,float *np,float *net,float *avgpr);//3.6 AddDetailToAccumulator
void PrintSummaryReport(float pr,float reg,float ovt,float gp,float fedt,float stt,float sst,float def,float np,float *avgpr,float avgreg,float avgovt, 
                        float avggp,float avgfedt,float avgstt,float avgsst,float avgdef,float avgnp,FILE * ReportFile); //3.7

int main()
    {
     EmployeeRecord r; // Call Employee Record Definitions
     float reghours,ovthours; 
     float ft,st,ssit;
     float pr,reg,ovt,gp,fedt,stt,sst,def,np;
     float avgpr,avgreg,avgovt,avggp,avgfedt,avgstt,avgsst,avgdef,avgnp;
     char answer;
     int empCount,count;
     FILE * ReportFile;

     PrintReportHeadings(ReportFile); //Call 3.1 PrintReportHeadings      

     empCount = 0;// count initializations  
     pr = reg = ovt = gp = fedt = stt = def = sst = np = 0;
     avgpr = avgreg = avgovt = avggp = avgfedt = avgstt = avgsst = avgdef = avgnp = 0;
     do
       {
         InputEmployeeData(count,r.firstname,r.lastname,&r.payrate,&r.defr,&r.hours);//Call 3.3 InputEmployeeData   
         if (r.hours > 40)//Check for Overtime Hours
           {
             reghours = 40;
             ovthours = r.hours - 40;
           }
         else {
             reghours = r.hours;
             ovthours = 0;
         }
          r.gross = CalculateGross(r.hours,r.payrate,reghours,ovthours); //3.4 CalculateGross
          CalculateTaxes(r.gross,r.defr,&ft,&st,&ssit);//Call 3.5 CalculateTaxes

          r.net = r.gross - ft - st - ssit;// Calculate Net Earnings

          printf(REPORTCOLUMNHEADINGS1);
          printf(REPORTCOLUMNHEADINGS2);
          printf(BARS); 
          printf(REPORTCOLUMN1,r.lastname,r.firstname,r.payrate,reghours,r.gross,ft,ssit,r.net); 
          printf(REPORTCOLUMN2,ovthours,st,r.defr);   
          ReportFile = fopen("report.txt", "a");
          fprintf(ReportFile,REPORTCOLUMN1,r.lastname,r.firstname,r.payrate,reghours,r.gross,ft,ssit,r.net); 
          fprintf(ReportFile,REPORTCOLUMN2,ovthours,st,r.defr); 
          fclose(ReportFile);

          AddDetailToAccumulator(count,&empCount,&pr,&r.payrate,&reg,&reghours,&ovt,&ovthours,&gp,&r.gross,&fedt,&ft,&stt,&st,&sst,&ssit,
                                 &def,&r.defr,&np,&r.net,&avgpr);//3.6


              while (getchar() != '\n');
              printf(" Repeat (Y/N)? : ");
              scanf("%c",ADDR(answer)); 
        } while (answer == 'Y' || answer == 'y');
            printf("\n"); // print one line for spacing         
       printf("\nTotals %17.2f%8.2f%10.2f%8.2f%8.2f%9.2f\n",pr,reg,gp,fedt,sst,np); 
       printf("%32.2f%18.2f%8.2f\n",ovt,stt,def); 

       printf("%d",count);

       printf("\nAverages %15.2f%8.2f%10.2f%8.2f%8.2f%9.2f\n",avgpr,avgreg,avggp,avgfedt,avgstt,avgnp); 
       printf("%32.2f%18.2f%8.2f\n",avgovt,avgsst,avgdef);

       PrintSummaryReport(pr,reg,ovt,gp,fedt,stt,sst,def,np,&avgpr,avgreg,avgovt,
                        avggp,avgfedt,avgstt,avgsst,avgdef,avgnp,ReportFile); //Call 3.7 PrintSummaryReport       

        fflush(stdin);
        getchar();
        return 0;
}

void PrintReportHeadings(FILE * ReportFile) //3.1
{
    ReportFile = fopen("report.txt", "w");
    fprintf(ReportFile,REPORTCOLUMNHEADINGS1);
    fprintf(ReportFile,REPORTCOLUMNHEADINGS2);
    fprintf(ReportFile,BARS);
    fclose(ReportFile);
}

void InputEmployeeData(int count,char * lastname,char * firstname, float * payrate, float * defr, float * hours) //3.3
{
     printf("Enter employee's name: ");  // input section
     scanf("%s%s",firstname,lastname);
     printf("Enter hourly pay rate: ");
     scanf("%f",payrate);
     printf("Enter deferred amount: ");
     scanf("%f",defr);
     printf("Enter hours worked this pay period: ");
     scanf("%f",hours);
}

float CalculateGross(float hours, float payrate, float reghours, float ovthours) // 3.4
{
    return (reghours * payrate)+(ovthours * payrate * 1.5);
}

void AddDetailToAccumulator(int *empCount,float *pr,float *payrate,float *reg,float *reghours,float *ovt,float *ovthours,float *gp,
                                float *gross,float *fedt,float *ft,float *stt,float *st,float *sst,float *ssit,float *def,
                                float *defr,float *np,float *net,float *avgpr)//3.6
{
         empCount = empCount +1;
         *pr = *pr + *payrate;
         *reg = *reg + *reghours;
         *ovt = *ovt + *ovthours;
         *gp = *gp + *gross;
         *fedt = *fedt + *ft; 
         *stt = *stt + *st; 
         *sst = *sst + *ssit;
         *def = *def + *defr;
         *np = *np + *net; 

         *avgpr = *pr / empCount;        
} 


void PrintSummaryReport(float pr,float reg,float ovt,float gp,float fedt,float stt,float sst,float def,float np,float * avgpr,float avgreg,float avgovt, 
                        float avggp,float avgfedt,float avgstt,float avgsst,float avgdef,float avgnp,FILE * ReportFile) //3.7
{
     ReportFile = fopen("report.txt", "a");
     fprintf(ReportFile,"\nTotals %17.2f%8.2f%10.2f%8.2f%8.2f%9.2f\n",pr,reg,gp,fedt,sst,np); 
     fprintf(ReportFile,"%32.2f%18.2f%8.2f\n",ovt,stt,def); 
     fprintf(ReportFile,"\nAverages %15.2f%8.2f%10.2f%8.2f%8.2f%9.2f\n",&avgpr,avgreg,avggp,avgfedt,avgsst,avgnp); 
     fprintf(ReportFile,"%32.2f%18.2f%8.2f\n",avgovt,avgstt,avgdef);
     fclose(ReportFile);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:39:30+00:00Added an answer on June 9, 2026 at 4:39 am

    As the previous answer pointed out, you were missing the * operator. This is known as the dereference operator.

    What you were doing:

    empCount = empCount +1;
    // or
    empCount++;     // Same assignment
    

    Here, you were performing pointer arithmetic. This assignment is advancing the pointer to the next integer.

    What you needed to do:

    (*empcount)++;
    

    Dereferencing the pointer will increment the value that the pointer points to. In other words, if the value of the pointer had address 0x01, the above line would access the integer at memory location 0x01 and add one to it. The original code would just increment the pointer to the next integer (Would increment to 0x05 for a 32-bit integer).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The the code for that portion, if you want to compile it is below.
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have a code like this below in /root_project/main.cpp : #include theoraplayer/TheoraVideoClip.h unsigned int
What is the main purpose of overloading operators in C++? In the code below,
I have a Fortran numerical code that calls a subroutine from an external module.
http://www.coffeeproteindrink.com/method-athlete/ I am trying to remove the open space below the main wrapper, in
Below is my main activity file. I am stuck with the bottom area (commented
In the below shown html i have this main div as cxfeeditem feeditem and
(In short: main()'s WaitForSingleObject hangs in the program below). I'm trying to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.