I have the following program:
#include <stdio.h>
int main (void)
{
int n, number, employeeNumber,counter;
float wage,hours,grossPay;
grossPay = wage*hours;
for ( counter = 1; counter <=5; ++counter) {
printf ("Enter Clock#:");
scanf ("%i",&number);
printf ("Enter Wage:");
scanf ("%f",&wage);
printf ("Enter Hours:");
scanf ("%f",&hours);
employeeNumber = 0;
for ( n = 1; n <= number; ++n)
employeeNumber +=n;
printf ("--------------------------------\n");
printf ("Clock# Wage Hours Gross\n");
printf ("--------------------------------\n");
printf ("%06i %.02f %.01f %f\n\n", number, wage, hours,grossPay);
}
return 0;
}
When I run the program, grossPay currently comes out to zero. I want grossPay to equal wage*hours, and it will depends on what I type in as the wage and hours for that clock number. Can anyone provide a tip on how to go about this? Thanks!
Move this line
after
You should try to calculate
grossPayafter user inputswage&hours. By default during declarationwageandhourswill be initialized to default value i.e.0.0and hence you are gettinggrossPayzero.