Compiling warning: Output is garbage. Don't understand warning at compiling
HI! I'm working on my program that takes input of the employees' first and last name, their payrate, their deferred from check and also the amount of hours they have worked which then the gross is calculated and also the taxes are calculated by an external function. In the program design it is necessary to put arrays which I have done, but when i compile I receive warning messages
Code:
warning: format '%s' expects argument of type 'char*', but argument 3 has type 'double'
warnning: format '%f' expects a matching 'double' argument [-Wformat]
which I believe is causing my program to just give me garbage when I run it. What do those warnings mean?
Code:
/* Name: Arturo
Date: 03/22/13
Purpose: To learn
*/
extern void calculatetaxes(float gross,float deferred, float *ft, float *st, float ........i);
void ovtHrs(float *hrs_wrk, float *ovt_hrs, float hrs, float *gross, float payrate);
void netPay(float gross, float deferred, float ft, float st, float ssi, float *net);
void calcAccumulator(float *tot_payrate, float payrate, float *tot_hrs_wrk, float hrs_wrk, float *tot_ovt, float ovt_hrs,
float *tot_gross, float gross, float *tot_ft, float ft, float *tot_st, float st, float *tot_ssi, float ssi,
float *tot_deferred, float deferred, float *tot_net, float net);
void calcAverage(float tot_payrate, float *payrate_avg, float tot_hrs_wrk, float *hrs_wrk_avg, float tot_ovt, float *ovt_avg,
float tot_gross, float *gross_avg, float tot_ft, float *ft_avg, float tot_st, float *st_avg, float tot_ssi,
float ........i_avg, float tot_deferred, float *deferred_avg, float tot_net, float *net_avg);
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define BLANKLINES " \n\n"
#define REPORTHEADER "Employee Pay Reg Hrs Gross Fed SSI Net\n"
#define REPORTHEADER1 "Name Rate Ovt Hrs Pay State Defr Pay\n"
#define REPORTHEADER2 "========= ====== ========= ======= ======= ====== =====\n"
#define REPORTFORMAT "%2s %2s %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"
#define REPORTFORMAT1 " %24.2f %36.2f %12.2f\n"
#define REPORTFORMAT2 "Totals%22.2f%16.2f%18.2f%19.2f%15.2f%11.2f\n"
#define REPORTFORMAT3 " %39.2f%37.2f%15.2f\n"
#define REPORTFORMAT4 "Averages%20.2f%16.2f%18.2f%19.2f%15.2f%11.2f\n"
#define REPORTFORMAT5 " %38.2f%37.2f%15.2f\n"
#define ARRAYSIZE 5
int main(void)
{
char lastname[ARRAYSIZE][10+1], firstname[ARRAYSIZE][15+1];
char S_name[15+10+3+2];
float payrate[ARRAYSIZE], hrs_wrk[ARRAYSIZE], ovt_hrs[ARRAYSIZE], gross[ARRAYSIZE], ft[ARRAYSIZE], st[ARRAYSIZE], ssi[ARRAYSIZE], deferred[ARRAYSIZE], net[ARRAYSIZE], hrs[ARRAYSIZE];
float tot_payrate=0, tot_hrs_wrk=0, tot_ovt=0, tot_gross=0, tot_ft=0, tot_st=0, tot_ssi=0, tot_deferred=0, tot_net=0;
float payrate_avg, hrs_wrk_avg, ovt_avg, gross_avg, ft_avg, st_avg, ssi_avg, deferred_avg, net_avg;
int i;
for(i=0; i<ARRAYSIZE; i++)
{
printf("Enter the last name of the employee\n");
scanf("%s", lastname[i]);
printf("Enter the first name of the employee\n");
scanf("%s", firstname[i]);
printf("Enter the the pay of the employee\n");
scanf("%f", &payrate[i]);
printf("Enter the amount of hours worked\n");
scanf("%f", &hrs[i]);
printf("Enter the deferred amount\n");
scanf("%f", &deferred[i]);
}
printf(BLANKLINES);
printf(REPORTHEADER);
printf(REPORTHEADER1);
printf(REPORTHEADER2);
for(i=0; i<ARRAYSIZE; i++)
{
strcpy(S_name, lastname[i]);
strcat(S_name, ", ");
strcat(S_name, firstname[i]);
ovtHrs(&hrs_wrk[i], &ovt_hrs[i], hrs[i], &gross[i], payrate[i]);
calculatetaxes(gross[i], deferred[i], &ft[i], &st[i], &ssi[i]);
netPay(gross[i], deferred[i], ft[i], st[i], ssi[i], &net[i]);
calcAccumulator(&tot_payrate, payrate[i], &tot_hrs_wrk, hrs_wrk[i], &tot_ovt, ovt_hrs[i], &tot_gross, gross[i], &tot_ft, ft[i], &tot_st, st[i], &tot_ssi, ssi[i], &tot_deferred, deferred[i], &tot_net, net[i]);
calcAverage(tot_payrate, &payrate_avg, tot_hrs_wrk, &hrs_wrk_avg, tot_ovt, &ovt_avg, tot_gross, &gross_avg, tot_ft, &ft_avg, tot_st, &st_avg, tot_ssi, &ssi_avg, tot_deferred, &deferred_avg, tot_net, &net_avg);
printf(BLANKLINES);
printf(REPORTFORMAT, S_name, payrate[i], hrs_wrk[i], gross[i], ft[i], ssi[i], net[i]);
printf(REPORTFORMAT1, ovt_hrs[i],st[i], deferred[i]);
}
printf(REPORTFORMAT2, tot_payrate, tot_hrs_wrk, tot_gross, tot_ft, tot_ssi, tot_net);
printf(REPORTFORMAT3, tot_ovt, tot_st, tot_deferred);
printf(REPORTFORMAT4, payrate_avg, hrs_wrk_avg, ovt_avg, gross_avg, ft_avg, st_avg, ssi_avg, deferred_avg, net_avg);
printf(REPORTFORMAT5, ovt_avg, st_avg,deferred_avg);
while(getchar()!= '\n');
getchar;
return 0;
}
void ovtHrs(float *hrs_wrk, float *ovt_hrs, float hrs, float *gross, float payrate)
{
if(hrs<=40)
{
*ovt_hrs=0;
*hrs_wrk=hrs;
*gross=hrs*payrate;
}
else
{
*hrs_wrk=40;
*ovt_hrs=hrs-40;
*gross=payrate*40+(hrs-40)*1.5*payrate;
}
}
void netPay(float gross, float deferred, float ft, float st, float ssi, float *net)
{
*net=gross-deferred-ft-st-ssi;
}
void calcAccumulator(float *tot_payrate, float payrate, float *tot_hrs_wrk, float hrs_wrk, float *tot_ovt, float ovt_hrs, float *tot_gross, float gross, float *tot_ft, float ft, float *tot_st, float st, float *tot_ssi, float ssi,float *tot_deferred, float deferred, float *tot_net, float net)
{
*tot_payrate+=payrate;
*tot_hrs_wrk+=hrs_wrk;
*tot_ovt+=ovt_hrs;
*tot_gross+=gross;
*tot_ft+=ft;
*tot_st+=st;
*tot_ssi+=ssi;
*tot_deferred+=deferred;
*tot_net+=net;
}
void calcAverage(float tot_payrate, float *payrate_avg, float tot_hrs_wrk, float *hrs_wrk_avg, float tot_ovt, float *ovt_avg, float tot_gross, float *gross_avg, float tot_ft, float *ft_avg, float tot_st, float *st_avg, float tot_ssi, float ........i_avg, float tot_deferred, float *deferred_avg, float tot_net, float *net_avg)
{
*payrate_avg=(tot_payrate/5);
*hrs_wrk_avg=(tot_hrs_wrk/5);
*ovt_avg=(tot_ovt/5);
*gross_avg=(tot_gross/5);
*ft_avg=(tot_ft/5);
*st_avg=(tot_st/5);
........i_avg=(tot_ssi/5);
*deferred_avg=(tot_deferred/5);
*net_avg=(tot_net/5);
}
No error message(s) just warnings
Quote:
Originally Posted by
jimblumberg
Yes quite possibly the cause of your problems. The scanf(), printf() functions are very particular about the format specifiers matching the arguments. Your messages are saying that your arguments don't match. Your error message should also be telling you the line that is causing the problem, you left out that information.
Jim
I'm not getting any error message(s). The only things that are being reported when i type 'make' are those two warnings. The third argument is supposed to be a double; why it is being labeled as a char beats me. I've been looking at my code for a while now o.O