Proper syntax of Do while and sentinel in a multi-function program

Below I have a payroll application that is fully functional but it doesn't work the way that I would like it to. I have stared at it for a couple hours and I've worn Google out looking for some tips and in the process I landed here. I believe my problem stems from the sentinel value that I'm trying to use to end the program. I think I have it in the right spot for the main function but I'm not sure. Also I am using a void function to display the calculated data per employee and that should be kosher but I need a separate function to calculate and display the total gross pay once the sentinel has ended the main function. I'm not sure what or where that totalGrossPay function should be. Should I assign each gross that is calculated by the main function to a variable and then sum those variables when the sentinel is called? Or should I create some type of running total function that increases as each gross is calculated? Thanks in advance for any and all help you can provide.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<iostream>
#include<iomanip>
using namespace std;

double ot = 0;
double getHoursWorked();
double getPayRate();
double calcGross(double&, double);
void displayData(double, double, double, double);

int main()
{

double hours = 0.0, rate = 0.0, gross = 0.0;

do
{
hours = getHoursWorked();
rate = getPayRate();
gross = calcGross(hours, rate);
displayData(hours,rate,ot,gross);
} while (hours != -1);


system("pause");
return 0;
}

double getHoursWorked()
{
double hrs;
cout << "enter the number of hours worked or -1 to quit: ";
cin >> hrs;
return hrs;
}
double getPayRate()
{
double pay;
cout << " enter your pay rate: $";
cin >> pay;
return pay;
}
double calcGross(double &hrs, double pay)
{
if(hrs >40)
{
ot = hrs - 40;
hrs = 40;
}
return (hrs * pay) + (ot * pay * 1.5);
}
void displayData(double hrs, double pay, double overTime, double grs)
{
cout << fixed << setprecision(2);
cout << "\nReg hours worked:" << setw(9)<< right << hrs << endl;
cout << "Over Time worked:" << setw(9) << right << overTime << endl;
cout << "Rate of Pay: " << setw(9) << right << pay << endl;
cout << "Gross Pay: " << setw(9) << right << grs << endl;
cout << "\n\n";
}

The issue is not the [code]do....while()[/condition], it's an issue of floats being imprecise, you would need to make a function that compares the float to within reason of -1 (Such as within +/- 0.0001). You could allow the user to enter any negative number to exit, then just test to see if the float is negative.
thanks for your input Intrexa; could you go into a little bit more detail as to why my floats are imprecise and what i can do to fix them. I did not understand this statement: "compares the float to within reason of -1 (Such as within +/- 0.0001)" . Also about the question of calculating and displaying the gross total once the user has exited the main function; How exactly would i do this? Thanks in advance.
closed account (z05DSL3A)
why my floats are imprecise and what i can do to fix them.

Big read time....

What Every Computer Scientist Should Know About Floating-Point Arithmetic
http://www-users.math.umd.edu/~jkolesar/mait613/floating_point_math.pdf
your program is Logically wrong..
Why did you use a Function
double SampleVariable(parameters);?
don't you know that functions has only 4 forms.

1.) void w/o parameters
2.)void w parameter
3.)return w/o parameters
4.)return w. parameters.
closed account (z05DSL3A)
(ypmick2007) ??
Topic archived. No new replies allowed.