Question

i am having trouble displaying results and displaying them evenly it is suppose to look like...

i am having trouble displaying results and displaying them evenly

it is suppose to look like this

Enter the following data for employee 1:
Employee ID: 1298
Hours worked: 35.8
Pay rate (per hour): 23.45

Enter the following data for employee 2:
Employee ID: 1899
Hours worked: 34.5
Pay rate (per hour): 19.5

Enter the following data for employee 3:
Employee ID: 4435
Hours worked: 30.5
Pay rate (per hour): 20.75

Enter the following data for employee 4:
Employee ID: 1308
Hours worked: 39.4
Pay rate (per hour): 26.75

Enter the following data for employee 5:
Employee ID: 9894
Hours worked: 40
Pay rate (per hour): 34.5


Weekly Payroll
--------------

Emloyee ID Hours Worked Pay Rate Gross Pay
---------- ------------ -------- ---------
1298 35.80 23.45 839.51
1899 34.50 19.50 672.75
4435 30.50 20.75 632.88
1308 39.40 26.75 1053.95
9894 40.00 34.50 1380.00

Press any key to continue . . .

hoursworked: 35.8

Pay rate per hour: 23.45

pay rate
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void getData(string [], double[], double [], double []);


void calculateGrossPay(double[], double[], double[]);

void displayOutput(string [], double[], double [], double []);
/*
void displayOutput();
*/
const int NUMBER_OF_EMPLOYEES = 5, EMPLOYEE_ID_LENGTH = 4;
int main()
{

   string employeeID[NUMBER_OF_EMPLOYEES];
   double hoursWorked[NUMBER_OF_EMPLOYEES], payRate[NUMBER_OF_EMPLOYEES], grossPay[NUMBER_OF_EMPLOYEES];
   //look at powerpoint 35-37
  
   getData(employeeID, hoursWorked, payRate, grossPay);
  
   calculateGrossPay(hoursWorked, payRate, grossPay);
  
   displayOutput(employeeID, hoursWorked, payRate, grossPay);
   return 0;
}
void getData(string employeeID [], double hoursWorked [], double payRate [], double grossPay [])
{
   for(int index = 0; index < NUMBER_OF_EMPLOYEES; index ++)
   {
       cout << "Enter the following dat for employee " << index + 1 << "\n\n";
       cout << "Employee ID: ";
       getline(cin, employeeID[index]);
      
       while (employeeID[index].length() != EMPLOYEE_ID_LENGTH)
       {
           cout << "Employee ID must be 4 characters long.\n\n"
               << "Enter the Employee ID: ";
           getline(cin, employeeID[index]);
       }
      
       cout << "Hours worked: ";
       cin >> hoursWorked[index];
      
       while (hoursWorked[index] < 0)
       {
       cout << "Please enter a valid numbers of hours worked: ";
       cin >> hoursWorked[index];
       }
      
       cout << "Pay rate (per hour): ";
       cin >> payRate[index];
      
       while (payRate[index] <= 0)
       {
       cout << "Error. Pay rate must be higher than 0."
           << "\nPay rate (per hour): ";
       cin >> payRate[index];
       }
      
   for(int index = 0; index < NUMBER_OF_EMPLOYEES; index ++)
   {
       grossPay[index] = hoursWorked[index] * payRate[index];
   }
   }
}

void calculateGrossPay(double hoursWorked [], double payRate [], double grossPay [])
{
   for(int index = 0; index < NUMBER_OF_EMPLOYEES; index ++)
   {
       grossPay[index] = hoursWorked[index] * payRate[index];
   }
}

void displayOutput(string employeeID [], double hoursWorked [], double payRate [], double grossPay [])
{
  
   int w = 10;
   cout << left << setw(18) << "Employee ID"
       << right << setw(w) << "Hours Worked"
       << setw(w) << "Pay Rate"
       << setw(w) << "Gross Pay" << endl;  
         
   cout << left << setw(w) << "------------- "
       << right << setw(w) << "------------ "
       << setw(w) << "--------"
       << setw(w) << "---------" <<endl;
   cout << setprecision(2) << fixed;  
  
   for (int index = 1; index <= NUMBER_OF_EMPLOYEES; index++)
   {
       int w = 10;
   cout << left << setw(w) << employeeID[index]
       << right << setw(w) << hoursWorked
       << setw(w) << payRate
       << setw(w) << grossPay << endl;  
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

//function prototypes
void getData(string [], double[], double [], double []);
void calculateGrossPay(double[], double[], double[]);
void displayOutput(string [], double[], double [], double []);

//constants declaration
const int NUMBER_OF_EMPLOYEES = 5, EMPLOYEE_ID_LENGTH = 4;

int main()
{
   //declare arrays to store the data
    string employeeID[NUMBER_OF_EMPLOYEES];
    double hoursWorked[NUMBER_OF_EMPLOYEES], payRate[NUMBER_OF_EMPLOYEES], grossPay[NUMBER_OF_EMPLOYEES];
    //look at powerpoint 35-37

   //get the employee details using getData function
    getData(employeeID, hoursWorked, payRate, grossPay);
   //calculate the gross pay using calculateGrossPay function
    calculateGrossPay(hoursWorked, payRate, grossPay);
   //display the payroll using deisplayOutput function
    displayOutput(employeeID, hoursWorked, payRate, grossPay);

    return 0;
}

//function that read the employee details from the user
void getData(string employeeID [], double hoursWorked [], double payRate [], double grossPay [])
{
   //run a loop to read details of each employee
   for(int index = 0; index < NUMBER_OF_EMPLOYEES; index ++)
    {
        //prompt and read employee id
       cout << "Enter the following data for employee " << index + 1 << "\n";
          cout << "Employee ID: ";
          getline(cin, employeeID[index]);
    
         //check if the employee id entered is valid
          while (employeeID[index].length() != EMPLOYEE_ID_LENGTH)
          {
              //display error message and re-prompt if employee id is not valid
           cout << "Employee ID must be 4 characters long.\n\n"
               << "Enter the Employee ID: ";
              getline(cin, employeeID[index]);
        }  
    
         //prompt and read hours worked
          cout << "Hours worked: ";
          cin >> hoursWorked[index];
    
         //check if the input is valid
          while (hoursWorked[index] < 0)
          {
              //display error message and re-prompt if invalid
              cout << "Please enter a valid numbers of hours worked: ";
              cin >> hoursWorked[index];
          }
    
         //prompt and read pay rate
          cout << "Pay rate (per hour): ";
          cin >> payRate[index];
    
         //check if input is valid
          while (payRate[index] <= 0)
          {
              //display error message and re-prompt if input is invalid
              cout << "Error. Pay rate must be higher than 0."
                  << "\nPay rate (per hour): ";
              cin >> payRate[index];
          }
         cout << endl;
        cin.ignore();
    }
}

//function that calculates gross pay of each employee
void calculateGrossPay(double hoursWorked [], double payRate [], double grossPay [])
{
   //run a loop that iterates through each employee
   for(int index = 0; index < NUMBER_OF_EMPLOYEES; index ++)
    {
        //calculate the gross pay of each employee
        grossPay[index] = hoursWorked[index] * payRate[index];
    }
}

//function that display the output
void displayOutput(string employeeID [], double hoursWorked [], double payRate [], double grossPay [])
{
   int w = 15;
   //display the header
   cout << "Weekly Payroll" << endl;
   cout << "--------------" << endl;
    cout << left << setw(20) << "Employee ID"
       << left << setw(w) << "Hours Worked"
          << setw(w) << "Pay Rate"
          << setw(w) << "Gross Pay" << endl;
       
    cout << left << setw(20) << "------------- "
          << left << setw(w) << "------------ "
              << setw(w) << "--------"
              << setw(w) << "---------" <<endl;
   cout << setprecision(2) << fixed;

   //run a loop that iterates through each employee
   for (int index = 1; index <= NUMBER_OF_EMPLOYEES; index++)
   {
        //display the employee payroll
        cout << left << setw(20) << employeeID[index-1]
              << left << setw(w) << hoursWorked[index-1]
              << setw(w) << payRate[index-1]
              << setw(w) << grossPay[index-1] << endl;
   }
}

Output:

Program Screenshot:

Add a comment
Know the answer?
Add Answer to:
i am having trouble displaying results and displaying them evenly it is suppose to look like...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursW...

    This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursWorked, payrate; float salary; cin>>choice; if(choice == 1){ cout<<"Enter your salary per month: "; cin>>salary; }else{ cout<<"Enter hours worked: "; cin>>hoursWorked; cout<<"Enter pay rate: "; cin>>payrate; salary = hoursWorked * payrate; } return salary; } void printCheck(float sal, int id, char address[30]){ cout<<"Employee id: "<>id; cout<<"Enter address: "; char...

  • Using the code below (C++), add a struct with only 1 vector #include #include #include //...

    Using the code below (C++), add a struct with only 1 vector #include #include #include // Needed to define vectors using namespace std; int main() { vector hours; // hours is an empty vector vector payRate; // payRate is an empty vector int numEmployees; // The number of employees int index; // Loop counter // Get the number of employees. cout << "How many employees do you have? "; cin >> numEmployees; // Input the payroll data. cout << "Enter...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

  • I am trying to modify this program so that it stores the employee's name in a...

    I am trying to modify this program so that it stores the employee's name in a c-string and can handle up to 100 employees (so it would mostly be a partially filled array), but I cannot get it to work. It works with two files that it is suppose to read input from. Then it prints output to an output file. Employee Info File (first file read, M/F should be ignored): 5    Christine Kim 30.00   2       1    F 15    Ray...

  • I was wondering if I could get some help with a Java Program that I am...

    I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...

  • // I am going to use if and else stamtents for this employee pay clalulations. //using...

    // I am going to use if and else stamtents for this employee pay clalulations. //using if and else to cal salary //If hours worked is <= 40.0 //Employee salry will = hours*pay rate //else //employess salary will =40*pay rate +(hours worked-40)*1.5* pay rate. #include using namespace std; const double Max_Hours= 40.0; const double MuLTIPLER = 1.5; char salary; char payrate; char hours_worked; char Max_hours; char get_total_pay; int main() { double Hours=0; double Payrate = 0; cout <<"Please enter employee...

  • Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All...

    Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate;       } int main(){    //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y";    //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...

    HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private int empNumber;    private double hoursWorked;    private double payRate;       private static int hospitalEmployeeCount = 0;    //-----------------------------------------------------------------    // Sets up this hospital employee with default information.    //-----------------------------------------------------------------    public HospitalEmployee()    { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0;               hospitalEmployeeCount++;    }       //overloaded constructor.    public HospitalEmployee(String eName,...

  • Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import...

    Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import java.util.*; public class SalaryCalc { public static void main(String [] args) { Scanner input = new Scanner(System.in); int sentinelValue = 1; //initializes sentinelValue value to 1 to be used in while loop while (sentinelValue == 1) { System.out.println("Enter 1 to enter employee, or enter 2 to end process: ");    sentinelValue = input.nextInt(); input.nextLine(); System.out.println("enter employee name: "); String employeeName = input.nextLine(); System.out.println("enter day...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT