I'm trying to turn this part into a function into my code -
-
grosspay = (hours * rate);
-
if (hours > 40)
-
grosspay = ((hours - 40) * rate * 1.5) + (40 * rate);
-
if (hours > 60)
-
grosspay = ((hours - 60) * rate * 2) + (20 * rate * 1.5) +(40 * rate);
-
-
does anyone have a sugestion? whenever I do it I get errors. please help
heres the code -
-
#include <iostream>
-
#include <iomanip>
-
-
/* Function Prototype */
-
-
/* Main Program */
-
-
int main(void)
-
{
-
int empNum, sumh, sump;
-
double hours, rate, grosspay;
-
-
cout << setprecision(2) << setiosflags(ios::fixed);
-
-
cout << "Please enter the employee number (0 to stop): ";
-
cin >> empNum;
-
-
while (empNum != 0)
-
{
-
cout << "Hours: ";
-
cin >> hours;
-
cout << "Rate: ";
-
cin >> rate;
-
-
grosspay = (hours * rate);
-
if (hours > 40)
-
grosspay = ((hours - 40) * rate * 1.5) + (40 * rate);
-
if (hours > 60)
-
grosspay = ((hours - 60) * rate * 2) + (20 * rate * 1.5) +(40 * rate);
-
-
-
cout << "\nGross Pay is " << grosspay;
-
-
cout << "\n\nPlease enter the employee number (0 to stop): ";
-
cin >> empNum;
-
}
-
-
cout << "Please enter the first employee's hours: ";
-
cin >> hours;
-
-
cout << "Please enter the second employee's hours: ";
-
cin >> hours;
-
-
cout << "Please enter the third employee's hours: ";
-
cin >> hours;
-
-
cout << "Please enter the fourth employee's hours: ";
-
cin >> hours;
-
-
cout << "Please enter the fifth employee's hours: ";
-
cin >> hours;
-
-
cout << "Please enter the sixth employee's hours: ";
-
cin >> hours;
-
-
sumh = hours + hours + hours + hours + hours + hours;
-
-
cout << "\nThe total hours worked by all employees is " << sumh << endl;
-
-
-
cout << "Please enter the first employee's grosspay: ";
-
cin >> grosspay;
-
-
cout << "Please enter the second employee's grosspay: ";
-
cin >> grosspay;
-
-
cout << "Please enter the third employee's grosspay: ";
-
cin >> grosspay;
-
-
cout << "Please enter the fourth employee's grosspay: ";
-
cin >> grosspay;
-
-
cout << "Please enter the fifth employee's grosspay: ";
-
cin >> grosspay;
-
-
cout << "Please enter the sixth employee's grosspay: ";
-
cin >> grosspay;
-
-
sump = grosspay + grosspay + grosspay + grosspay + grosspay + grosspay;
-
-
cout << "\nThe total gross pay earned by employees is " << sump << endl;
-
-
return (0);
-
}
-
-
/* Function: GrossPay
-
* Usage: grosspay = GrossPay(hours, rate);
-
* ----------------------------------------
-
* This function calculates the gross pay for an employee for the
-
* given number of hours worked (hours) and the rate of pay (rate).
-
* An employee is paid at the regular rate for the first 40 hours worked,
-
* at 1.5 times the rate for any hours over the first 40, and
-
* at 2 times the rate for any hours over the first 60.
-
*
-
* e.g. 62 hours at $10 per hour,
-
* gives $400 for the first 40 hours,
-
* $300 for the next 20 hours, and
-
* $ 40 for the final 2 hours,
-
* ---- --
-
* thus $740 for the total 62 hours for a gross pay.
-
*/
-
6 1692 Banfa 9,065
Expert Mod 8TB
does anyone have a sugestion? whenever I do it I get errors. please help
Well then post what you have tried and the errors you are getting.
heres what i have but for hours over 60 the output is wrong but it should be right acording to the code..can you help?
#include <iostream>
#include <iomanip>
/* Function Prototype */
double grosspaycalc(int hours, int rate);
/* Main Program */
int main(void)
{
int empNum, sumh, sump;
double hours, rate, grosspay;
cout << setprecision(2) << setiosflags(ios::fixed);
cout << "Please enter the employee number (0 to stop): ";
cin >> empNum;
while (empNum != 0)
{
cout << "Hours: ";
cin >> hours;
cout << "Rate: ";
cin >> rate;
grosspay = grosspaycalc(hours, rate);
cout << "\nGross Pay is " << grosspay;
cout << "\n\nPlease enter the employee number (0 to stop): ";
cin >> empNum;
}
cout << "Please enter the first employee's hours: ";
cin >> hours;
cout << "Please enter the second employee's hours: ";
cin >> hours;
cout << "Please enter the third employee's hours: ";
cin >> hours;
cout << "Please enter the fourth employee's hours: ";
cin >> hours;
cout << "Please enter the fifth employee's hours: ";
cin >> hours;
cout << "Please enter the sixth employee's hours: ";
cin >> hours;
sumh = hours + hours + hours + hours + hours + hours;
cout << "\nThe total hours worked by all employees is " << sumh << endl;
cout << "Please enter the first employee's grosspay: ";
cin >> grosspay;
cout << "Please enter the second employee's grosspay: ";
cin >> grosspay;
cout << "Please enter the third employee's grosspay: ";
cin >> grosspay;
cout << "Please enter the fourth employee's grosspay: ";
cin >> grosspay;
cout << "Please enter the fifth employee's grosspay: ";
cin >> grosspay;
cout << "Please enter the sixth employee's grosspay: ";
cin >> grosspay;
sump = grosspay + grosspay + grosspay + grosspay + grosspay + grosspay;
cout << "\nThe total gross pay earned by employees is " << sump << endl;
return (0);
}
/* Function: GrossPay
* Usage: double grosspaycalc(int hours, int rate);
* ----------------------------------------
* This function calculates the gross pay for an employee for the
* given number of hours worked (hours) and the rate of pay (rate).
* An employee is paid at the regular rate for the first 40 hours worked,
* at 1.5 times the rate for any hours over the first 40, and
* at 2 times the rate for any hours over the first 60.
*
* e.g. 62 hours at $10 per hour,
* gives $400 for the first 40 hours,
* $300 for the next 20 hours, and
* $ 40 for the final 2 hours,
* ---- --
* thus $740 for the total 62 hours for a gross pay.
*/
double grosspaycalc(int hours, int rate)
{
if (hours <= 40)
return (hours * rate);
if (hours > 40)
return ((hours - 40) * rate * 1.5) + (40 * rate);
if (hours > 60)
return ((hours - 60) * rate * 2) + (20.0 * rate * 1.5) +(40 * rate);
return 0.0;
}
Banfa 9,065
Expert Mod 8TB
heres what i have but for hours over 60 the output is wrong but it should be right acording to the code..can you help?}
Well it looks right, give me an example of input and output where it goes wrong
Well it looks right, give me an example of input and output where it goes wrong
62 hours and 10 rate should be 740 but output says 730...
I got it guys, Thanks again
Banfa 9,065
Expert Mod 8TB
I got it guys, Thanks again
Tell us what it was please :D
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
is it possible to write python code without any indentation?
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
|
by: Alex Vinokur |
last post by:
C++ Simulator of a Nondeterministic Turing Machine has been added at :
* http://alexvn.freeservers.com/s1/turing.html
* http://sourceforge.net/projects/turing-machine/
Currently those sites...
|
by: Alex Vinokur |
last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at :
* http://alexvn.freeservers.com/s1/utm.html
* http://sourceforge.net/projects/turing-machine/
The program simulates a...
|
by: Kvele |
last post by:
I'm just looking for Turing machine for divide two binary numbers by
subtract. The input string of numbers can't be deleted. The result must
contain arrear. I need list of states (or c source). For...
|
by: Terry Reedy |
last post by:
http://campus.acm.org/public/pressroom/press_releases/3_2006/turing_3_01_2006.cfm
Peter Naur was co-developer of Backus/Naur grammar notation, co-author and
editor of the Algol 60 specification,...
|
by: roxorsoxor2345 |
last post by:
I am very sorry if this is not the appropriate group to post this
question.
I currently have a program that tests strings to see if they are
palindromes. My input file looks something like...
|
by: CoreyWhite |
last post by:
So I'm reading books about perl, which may not be quite as powerful as
C++ but at least has more power than C & is very easy to learn from
the manuals. I'm also buying books on C++, and books...
|
by: lovecreatesbea... |
last post by:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,
http://www.acm.org/classics/sep95/ . Can this be done in C? How...
|
by: orangemonkey |
last post by:
Hi guys. I'm practicing for the CCC, a programming competition. I got stuck on a problem, so I copied the problem's answer from turing into C++. When I run my program in C++ though, I get a different...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |