473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

turing into a function

I'm trying to turn this part into a function into my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. grosspay = (hours * rate);
  3.       if (hours > 40)
  4.       grosspay = ((hours - 40) * rate * 1.5) + (40 * rate);
  5.       if (hours > 60)
  6.       grosspay = ((hours - 60) * rate * 2) + (20 * rate * 1.5) +(40 * rate);
  7.  
  8.  


does anyone have a sugestion? whenever I do it I get errors. please help



heres the code

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. /* Function Prototype */
  6.  
  7. /* Main Program */
  8.  
  9. int main(void)
  10. {
  11.  int empNum, sumh, sump;
  12.    double hours, rate, grosspay;
  13.  
  14.    cout << setprecision(2) << setiosflags(ios::fixed);
  15.  
  16.    cout << "Please enter the employee number (0 to stop): ";
  17.    cin >> empNum;
  18.  
  19.    while (empNum != 0)
  20.    {
  21.     cout << "Hours: ";
  22.       cin >> hours;
  23.       cout << "Rate: ";
  24.       cin >> rate;
  25.  
  26.       grosspay = (hours * rate);
  27.       if (hours > 40)
  28.       grosspay = ((hours - 40) * rate * 1.5) + (40 * rate);
  29.       if (hours > 60)
  30.       grosspay = ((hours - 60) * rate * 2) + (20 * rate * 1.5) +(40 * rate);
  31.  
  32.  
  33.       cout << "\nGross Pay is " << grosspay;
  34.  
  35.       cout << "\n\nPlease enter the employee number (0 to stop): ";
  36.     cin >> empNum;
  37.    }
  38.  
  39.              cout << "Please enter the first employee's hours: ";
  40.              cin >> hours;
  41.  
  42.              cout << "Please enter the second employee's hours: ";
  43.              cin >> hours;
  44.  
  45.              cout << "Please enter the third employee's hours: ";
  46.              cin >> hours;
  47.  
  48.              cout << "Please enter the fourth employee's hours: ";
  49.              cin >> hours;
  50.  
  51.              cout << "Please enter the fifth employee's hours: ";
  52.              cin >> hours;
  53.  
  54.              cout << "Please enter the sixth employee's hours: ";
  55.              cin >> hours;
  56.  
  57.              sumh = hours + hours + hours + hours + hours + hours;
  58.  
  59.    cout << "\nThe total hours worked by all employees is " << sumh << endl;
  60.  
  61.  
  62.              cout << "Please enter the first employee's grosspay: ";
  63.              cin >> grosspay;
  64.  
  65.              cout << "Please enter the second employee's grosspay: ";
  66.              cin >> grosspay;
  67.  
  68.              cout << "Please enter the third employee's grosspay: ";
  69.              cin >> grosspay;
  70.  
  71.              cout << "Please enter the fourth employee's grosspay: ";
  72.              cin >> grosspay;
  73.  
  74.              cout << "Please enter the fifth employee's grosspay: ";
  75.              cin >> grosspay;
  76.  
  77.              cout << "Please enter the sixth employee's grosspay: ";
  78.              cin >> grosspay;
  79.  
  80.    sump = grosspay + grosspay + grosspay + grosspay + grosspay + grosspay;
  81.  
  82.    cout << "\nThe total gross pay earned by employees is " << sump << endl;
  83.  
  84.    return (0);
  85. }
  86.  
  87. /* Function: GrossPay
  88.  * Usage: grosspay = GrossPay(hours, rate);
  89.  * ----------------------------------------
  90.  * This function calculates the gross pay for an employee for the
  91.  * given number of hours worked (hours) and the rate of pay (rate).
  92.  * An employee is paid at the regular rate for the first 40 hours worked,
  93.  * at 1.5 times the rate for any hours over the first 40, and
  94.  * at 2 times the rate for any hours over the first 60.
  95.  *
  96.  *   e.g.  62 hours at $10 per hour,
  97.  *         gives $400 for the first 40 hours,
  98.  *           $300 for the next  20 hours, and
  99.  *         $ 40 for the final  2 hours,
  100.  *                   ----               --
  101.  *       thus  $740 for the total 62 hours for a gross pay.
  102.  */
  103.  
Nov 1 '06 #1
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.
Nov 1 '06 #2
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;
}
Nov 2 '06 #3
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
Nov 2 '06 #4
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...
Nov 2 '06 #5
I got it guys, Thanks again
Nov 2 '06 #6
Banfa
9,065 Expert Mod 8TB
I got it guys, Thanks again
Tell us what it was please :D
Nov 2 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

32
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
0
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...
0
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...
3
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...
6
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,...
1
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...
17
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...
11
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...
2
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...
0
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...
0
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...
0
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,...
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.