Need help with homework, due may 2nd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// weekly Time Card program
// ChrisH
// 4/27/12
// this program computes pay for all employees

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//Function prototypes
void inputEmployeeInfo (string[], float[], float[], int, int );
void computePay        (float, float[], float[], float[], float[],int, int );
void outputPayReport   ( string[], float[], float[], float[], float[], int );
/////////////////////

int main() 
{
   int numOfEmps;
   int size;
   size = numOfEmps;
   cout <<"Enter the number of Employees you wish to calculate pay for:" << endl; // initializing array size numOfEmps
   cin >> size;
   int counter;
   string names[numOfEmps];
   float hours[numOfEmps];
   float payrate[numOfEmps];
   float grossPay[numOfEmps];
   float netPay[numOfEmps];
   float OTpay;

//calling functions
void   inputEmployeeInfo ( names[numOfEmps], hours[numOfEmps], payrate[numOfEmps], numOfEmps );
void   computePay ( OTpay[numOfEmps],grossPay[numOfEmps], netPay[numOfEmps], hours[numOfEmps], payrate[numOfEmps],counter, numOfEmps );
void   outputPayReport ( names[numOfEmps], hours[numOfEmps], payrate[numOfEmps], grossPay[numOfEmps], netPay[numOfEmps], numOfEmps);

   return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start funtion 1
void inputEmployeeInfo ( string names[], float hours[], float payrate[], int  numOfEmps )
{

   int counter = 0;
   ofstream outputFile;
   outputFile.open ("empInfo.txt");

   while (counter < numOfEmps)
   {
     cout << "Enter the name of an employee:" << endl;
     cin >> names[counter];
     cout << "Enter the hourly pay rate for this employee:" << endl;
     cin >> payrate[counter];
     cout << "Enter the hours this employee worked this week:" << endl;
     cin >> hours[counter];

     outputFile << names[counter] << endl;
     outputFile << payrate[counter] << endl;
     outputFile << hours[counter] << endl;
     outputFile.close();
     counter++;
   }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 1
                                                       //
                                                       //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start function 2
void computePay(float OTpay, float grosspay[], float netpay[], float hours[], float payrate[],int counter, int numOfEmps )
{
   int index = 0;


   while (index < counter)
  {

      if (hours[index]>40)
        {
          OTpay = (hours[index] - 40)*1.5*payrate[index];
          grosspay[index] = OTpay + (hours[index] * payrate[index]);
          netpay[index] = grosspay[index] - (grosspay[index]*.03625);
        }
      else
      {
          grosspay[index] = hours[index] * payrate[index];
          netpay[index] = grosspay[index] - (grosspay[index] * .03625);
      }
 index++;
   }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 2
                                                               //
                                                               //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start function 3
void outputPayReport(string names[], float hours[], float payrate[], float grosspay[], float netpay[], int numOfEmps, int counter)
{

   int index = 0;
   cout << "______________________ your payroll sheet _______________________" << endl;

   while (index < counter)
   {
      cout << names[index] << "  " << payrate[index] << "  " << hours[index] << "  " << grosspay[index] << "  " << netpay[index] << endl;
       index ++;
   }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 3

accidentally removed original code here is repost ^
Last edited on
Successive forward slashes are confusing as lines 35 - 37 should be a comment. Use /*------*/ or something similar instead.
This compiles now, but didn't check the logic. I put // Changed where I changed things. I think I got them all.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// weekly Time Card program
// my name
// the date
// this program computes pay for all employees

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//Function prototypes
// Changed
void inputEmployeeInfo (string[], float[], float[], int );
void computePay        (float, float[], float[], float[], float[],int, int );
void outputPayReport   ( string[], float[], float[], float[], float[], int );
/////////////////////

int main() {
   int numOfEmps;
   int size;  
   size = numOfEmps;
   cout <<"Enter the number of Employees you wish to calculate pay for:" << endl; // initializing array size numOfEmps  
   cin >> size;     
   int counter;           
   string names[numOfEmps];
   float hours[numOfEmps]; 
   float payrate[numOfEmps];
   float grossPay[numOfEmps];
   float netPay[numOfEmps]; 
   float OTpay;            

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////calling functions/////////////////////
// Changed
   inputEmployeeInfo ( names, hours, payrate, numOfEmps );                                        //
   computePay ( OTpay,grossPay, netPay, hours, payrate,counter, numOfEmps );           //
   outputPayReport ( names, hours, payrate, grossPay, netPay, numOfEmps);      //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start funtion 1
void inputEmployeeInfo ( string names[], float hours[], float payrate[], int  numOfEmps ) {
// Changed
   int index(0);
   ofstream outputFile;
   outputFile.open ("empInfo.txt");

   while (index < numOfEmps) {
     cout << "Enter the name of an employee:" << endl;
     cin >> names[index];
     cout << "Enter the hourly pay rate for this employee:" << endl;
     cin >> payrate[index];
     cout << "Enter the hours this employee worked this week:" << endl;
     cin >> hours[index];
// Changed
     outputFile << names << endl;
     outputFile << payrate << endl;
     outputFile << hours << endl;
     outputFile.close();
     index++;
   }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 1
                                                       //
                                                       //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start function 2
void computePay(float OTpay, float grosspay[], float netpay[], float hours[], float payrate[],int counter, int numOfEmps ){
   int index(0);
   while (index < numOfEmps) {
      // Changed
      if (hours[index]>40) {
          OTpay = (hours[index] - 40)*1.5*payrate[index];
          grosspay[index] = OTpay + (hours[index] * payrate[index]);
          netpay[index] = grosspay[index] - (grosspay[index]*.03625);
      }
      else {
          grosspay[index] = hours[index] * payrate[index];
          netpay[index] = grosspay[index] - (grosspay[index] * .03625);
      }
      index++;
   }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 2
                                                               //
                                                               //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////start function 3
void outputPayReport(string names[], float hours[], float payrate[], float grosspay[], float netpay[], int numOfEmps) {
// Changed
   int index(0);
   cout << "______________________ your payroll sheet _______________________" << endl;

   while (index < numOfEmps) {
      cout << names[index] << "  " << payrate[index] << "  " << hours[index] << "  " << grosspay[index] << "  " << netpay[index] << endl;
       index ++;
   }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////end function 3 
histrungalot, you need to explain WHY you changed them. Just giving him the answers wont help him learn anything, he'll be back for the next assignment in no time if he doesn't know his mistakes...
the deadline has passed.
although the deadline has passed i do agree with Need4Sleep. having the "corrected code" did help my understanding a little bit but a formal explanation alongside that would have been very helpful..
Topic archived. No new replies allowed.