The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Write a program that will total your wages for a pay period. As a user, I should be asked to enter how many days I worked, the hours worked per each of those days, and then be asked for how much per hour I make. I should then see in a neatly formatted display, my total gross earnings for that pay period of days entered.
Â
Attached is what I have so far. I am having issues with it. I really do not comprehend C++.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void employee_info(FILE* fp, int* days, float* rate, float* hours);
float calc_gross_pay(float rate, float hours);
void display(FILE* fp, int days, float gross_pay);
int main()
{
   int days;
   float rate;
   float hours;
   float gross_pay;
   int nums;
   FILE *fpin;
   FILE *fpout;
   fpin = fopen("payperiod.in", "r");
   if(fpin == NULL)
   {
      printf("file 'payperiod.in' cannot be opened for reading\n");
      exit(1);
   }
   fpout = fopen("payperiod.out", "w");
   if (fpout == NULL)
   {
      printf("file 'employees.out' cannot be opened for writing");
      exit(1);
   }
   employee_info(fpin, &days, &rate, &hours);
   while (!feof(fpin))
   {
      nums++;
      gross_pay = calc_gross_pay(rate, hours);
      employee_info(fpin, &days, &rate, &hours);
   }
   fclose(fpin);
   fclose(fpout);
   return 0;
}
void employee_info(FILE* fp, int* days, float* rate, float* hours)
{
   fscanf(fp, "%d", days);
   fscanf(fp, "%f", rate);
   fscanf(fp, "%f", hours);
}
float calc_gross_pay(float rate, float hours)
{
   float gross_pay = 0;
   if (hours <= 40)
      gross_pay = rate * hours;
   else
      gross_pay = rate * 40 + (hours - 40) * rate * 1.5f;
   return gross_pay;
}
void display(FILE* fp, int days, float gross_pay)
{
   fprintf(fp, "%d %.2f\n", days, gross_pay);
   printf("%d %.2f\n", days, gross_pay);
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly