I have to write a code with a do-while loop where the user enters a set of data, and then the data is calculated based on constants and then the data has to printed onto an output file. I can only get one line to print to output file.
I have including the fprintf function within the do while loop but that doesnt work.
void GetInfo(void){
do {
printf("Enter staff member #%d's first name: ", count, name);
gets(name);
printf("Enter staff member #%d's last name: ", count, lastname);
gets(lastname);
printf("Enter the hourly wage of %s %s: ",name, lastname, wage);
scanf("%f", &wage);
printf("Enter total number of hours: ", hours);
scanf("%f", &hours);
printf("\n");
printf("Thank you. Process another employee? ");
scanf("%s", &answer);
clear();
printf("\n");
count++;
} while (answer == 'y' || answer == 'Y');
printf("End of processing.\n");
}
void DoCalcs(void){
overtimewage = wage*overtimerate;
if (hours > overtime){
reghours = overtime;
overtimehours = hours - overtime;
gross = (reghours*wage)+(overtimehours*overtimewage);
}
else{
reghours = hours;
overtimehours = 0;
gross = reghours*wage;
}
}
void ReportEarnings(void){
strcat(lastname, ", ");
strcat(lastname, name);
fprintf(reportfile, "%-15s %19.1f ($%.2f) %6.1f ($%.2f) $%10.2f\n", lastname, reghours, wage, overtimehours, overtimewage, gross);
}
The ReportEarning only prints the first entry of the loop in the output file but it needs to enter (and calculate) as many entries as there are in the loop.
Thanks for the help!
Aucun commentaire:
Enregistrer un commentaire