Ok, the teacher gave us a out-of-book program to write. Now she says that the program is doing the intention, but that she found "about 15 lines that can be done in a better manner". Now i'm sure there are 15, but based on what we have learned in class (because i can't apply things she hasn't taught for in-class work) i cannot rlly find anything. Could you please review/run my code and tell me what you may have done different? The only thing i truely hate is how i managed the deductions of the constants in the find_net function.
/* Edit: The iomanip is included because i plan to add a setiosflags line to format output. Thats not required so don't count that as an error*/
Code:
/* Steven Billington
December 20, 2002
NatPine.cpp
Program finds netpay for employees.
*/
#include "stdafx.h"
#include <iostream.h>
#include <iomanip.h>
/* Prototype functions*/
double find_gross(double &worked, double &rate);
double find_net(double &grosspay);
/* Const for deductions*/
const double FED_TAX = 0.18;
const double S_TAX = 0.045;
const double HOSP = 26.65;
const double UNION = 7.85;
int main(int argc, char* argv[])
{
/* Input/function calls*/
double hours,
hr_rate,
gross,
net_pay;
/* Prompt user*/
cout<<"Enter hours: ";
cin>>hours;
cout<<"Enter rate: ";
cin>>hr_rate;
/* Call function*/
gross = find_gross(hours,hr_rate);
cout<<"\nGross hours worked: "<<"\t"
<<gross<<endl;
/* Call function, output return*/
cout<<"\nNet pay is: "<<"\t\t"
<<find_net(gross)<<endl;
return 0;
}
/* Function definition*/
/* Function finds gross pay based on user
given values*/
double find_gross(double &worked, double &rate)
{
double gross_pay;
gross_pay = worked * rate;
return gross_pay;
}
/* Function Declaration*/
/* Function finds net pay based on return
of find_gross function by making
deductions*/
double find_net(double &grosspay)
{
double net_is,
percent_loss;
percent_loss = grosspay * FED_TAX;
grosspay -= percent_loss;
percent_loss = grosspay * S_TAX;
grosspay -= percent_loss;
grosspay -= HOSP;
grosspay -= UNION;
net_is = grosspay;
return net_is;
}