Functions. Inputfile and output files.

I have a pretty straight forward program I am having trouble with. I just want to get an int(hours) and a double(hourlypay) from an input file, multiply them, and write them to an output file using a function called CalNetPay. The CalNetPay function will do all the math and calculate and return as long as there is an int(hours) and a double(hourlypay) from the input file, so I'm assuming a while loop as well. Now, from viewing my code you can see I have a few errors. 1.) I don't really know what to put inside the function as far as doing the math. 2.) I'm not sure how to grab the returned CalNetPay and write it to the output file.
Please help.

Here's the instructions in case it helps.
heres the instructions in case it helps:

Write a program that calculates Net Pay. It should do this by calling a function called CalNetPay that calculates and returns Net Pay when given the hours worked and the hourly pay rate. The main function should pass the hours worked and pay rate to the function CalNetPay. The main function should get the hours worked and pay rates from a file called Lab12aInput.txt that you will create. From the main function print to an output file called Lab12Output.txt the Net Pay for each record in the Input file.
Lab12aInput should contain the following lines.
2 10.5
5 20
10 30.2
Your program should open the Input file and make sure the open was successful.
Your program should use a while Loop to process and read the data from the Input file. The while loop should continue execution as long as values are read from the file


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
  #include <iostream>
#include <fstream>

using namespace std;

//function prototype
int CalNetPay(int);

int main()
{
    ifstream infile;
    ofstream outfile;
    
    int hourly1;
    double wage1;
    
    
    cout << "This program calculates the Net Pay from Lab12aInput.txt to Lab12Output.txt" << endl;
    
    infile.open("Lab12aInput.txt")
    if (!infile)
    {
        cout << "File open failure" << endl;
    }
    else
    {
        while (infile >> houlry1 >> wage1)
            
            
    }
    infile.close();
    
    outfile.open("Lab12Output.txt")
    outfile.close();
    
    return 0;
}

int CalNetPay(NetPay)
{
    
}
Last edited on
Instructions wrote:
It should do this by calling a function called CalNetPay that calculates and returns Net Pay when given the hours worked and the hourly pay rate.

You have given only 1 int (hours, I suppose). Also function declaration and definition does not match (you need to write variable type here too)

About math: answer, how to get net payment, given worked hours and pay per hour?
Topic archived. No new replies allowed.