473,387 Members | 1,541 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,387 software developers and data experts.

Help with modular functions and looping

Okay, so I've gotten what I think is a good start on this project, not sure though. I am confused on how to make my program be able to run for 0 to an infinite number of employees. I know its a loop but not sure how to prompt int main to run again after computing for an employee. I'm assuming I need a kill command of like "5" to stop the program. Also, I'm confused on how to get information from my main to get the program to go to the correct next function based on the employee type. I appreciate any advice and help you can give me:).

Here are the project directions.

Create a program that calculates and displays (to 2 places of decimal) the weekly gross pay of hourly employees and salaried employees.
The weekly gross pay of a salaried employee is calculated by dividing the employee’s annual salary by 52.
The weekly gross pay of an Hourly employee is calculated by multiplying the number of hours worked by the pay rate.
Create two separate functions (one each for the Hourly employees and the Salaried employees) as follows:
 For the Hourly employee function, prompt for two values (hours worked and pay rate), and pass them to the function
 For the Salaried employee function, prompt for one value (yearly salary), and pass it to the function.
Continue to request, calculate and display employee information until there is no more employee data to process. Your program must be able to process zero employees, to an infinite number of employees.
Demonstrate the use of the following in your solution:
 Looping
 Modularity (using functions)
Prompt for the type of employee to process, and invoke the Hourly Employee function or the Salaried employee function, depending on the type of employee pay the program’s user wants to process.
Except for the number of weeks in a year (52), there must be no hard-coded input in your program.


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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include "File.hpp"
#include <iostream>
using namespace std;


int Salaryemp(float yrsal);
int Hourlyemp(float hr, float wage);
float hr;
float wage;
float yrsal;
int emp;

int main()
{

cout << "enter employee type (1 for hourly and 0 for a salaried employee):";
cin >> emp;

if (emp == 1) // 1 = a hourly employee.
{
cout << "Enter hours worked this week:";
cin >> hr;
cout << "Enter horly pay:";
cin >> wage;


}
else (emp = 0); // 0 = a salaried employee.
{
cout << "Enter yearly salary:";
cin >> yrsal;

}


}





int Hourlyemp()
{
return 0;
}



int Salaryemp()
{

cout << yrsal / 52 << "is the weekly pay";


return 0;
}
Mar 10 '18 #1
2 1490
weaknessforcats
9,208 Expert Mod 8TB
There are several issues here.

First, the main() is just the function called by the OS to start your program. Nothing special about it. In fact, you can tell your linker through a setting to call some other function than main(), if you want.

Second, your functions should do only one thing. The less a function does, the more places you can use it. Reuse of code is a big deal. It saves time recoding and debugging code that already exists.

So your program could look like this:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int exit = 0;
  4.     while (1)  <--- your infinite loop
  5.         {
  6.          if (exit == 1)
  7.          break;  <-- blows you out of while(1) and back to main(). This is your program exit
  8.  
  9.           int choice;
  10.             Display Menu();    
  11.            choice = GetChoice();
  12.            switch(choice)  
  13.            {
  14.              1: AddEmployee();  <--don't have the user enter the employee type. Make it part of the data.
  15.                 break;  <--takes you back to while (1)
  16.  
  17.              2: exit = GetExit();     <-- sets exit to 1
  18.                 break;     <-- back to while(1)
  19.  
  20.  
  21.         }
  22. }

What do you think?
Mar 11 '18 #2
weaknessforcats
9,208 Expert Mod 8TB
Next your employee data needs to be corralled so it stays together. If you don't know about C++ classes, start with a struct:

Expand|Select|Wrap|Line Numbers
  1. struct Employee
  2. {
  3.    float hr;
  4.    float wage;
  5.    float yrsal;
  6.    int emp;
  7. };
You would an instance of struct Employee and copy the instance to your storage array. You then clear the data in the instance and reuse it for the next Employee.
Mar 11 '18 #3

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

Similar topics

2
by: vinhkan | last post by:
just learning c++. trying out this small routine to demonstrate how to center text on the screen. It's a function called "int cent(int)" doesn't work for me. could you take a look for me. thanks...
21
by: cjl | last post by:
Hey all: I have the following (ugly) code: function preload() { if (cr_series.length >1) preloadCR(); if (ct_series.length >1) preloadCT(); if (mr_series.length >1) preloadMR(); if...
14
by: Brian | last post by:
#include <iostream> #include <cmath> using namespace std; int water_bill(int usage_in_cubic_meters); int main() { cout << "Enter the amount of usage in cubic meters: ";
1
by: palani12kumar | last post by:
hi friends, i need your help regarding functions. normally a function can return a single value to the calling function. what i have to do for returning more than one value at a time? is there...
0
by: swtstrawberry | last post by:
here are the directions and below the direction is what I have so far. I need help with (B) the bisect function. I've only posted part of my program, if more information is needed please let me...
8
by: monmon | last post by:
i have this code that needs to be loop nth time.. Sub Macro12() ' ' Macro12 Macro ' ' Range("A2:D6").Select
1
by: DreamOn | last post by:
Hi guys. Need some help with some functions. I'm using a table that lists all the records in my db table but i did a search form and i have been told that for me to do what i want i would have to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.