Answer to Question #184174 in C++ for Skye Jordan

Question #184174

Based on the question below, write a program using :

a. For loop

b. While loop

c. Do..while loop


Calculate the salary that employee get based on number of working. Rate of the payment is RM8.00 per hour but the salary will be deducted with 10% KWSP. By using a repetition control structure, write a program to calculate the total salary of 5 employees and the average salary of the employee. 


1
Expert's answer
2021-04-22T03:42:51-0400
#include <iostream>
using namespace std;

const double PAYMENT_RATE = 8.0;
const double KWSF = 0.1;
const int N = 5;

void salary1(double hours[N]) {
    double payment, tot_payment=0.0;


    for (int i=0; i<N; i++) {
        payment = (hours[i] * PAYMENT_RATE) * (1 - KWSF);
        cout << i+1 << " employee salary is RM" << payment << endl;
        tot_payment += payment;
    }
    cout << endl << "Average salary is " << tot_payment / N << endl << endl;
}


void salary2(double hours[N]) {
    double payment, tot_payment=0.0;
    int i=0;

    while(i<N) {
        payment = (hours[i] * PAYMENT_RATE) * (1 - KWSF);
        cout << i+1 << " employee salary is RM" << payment << endl;
        tot_payment += payment;
        i++;
    }
    cout << endl << "Average salary is " << tot_payment / N << endl << endl;
}


void salary3(double hours[N]) {
    double payment, tot_payment=0.0;
    int i=0;

    do {
        payment = (hours[i] * PAYMENT_RATE) * (1 - KWSF);
        cout << i+1 << " employee salary is RM" << payment << endl;
        tot_payment += payment;
        i++;
    } while (i<N);
    cout << endl << "Average salary is " << tot_payment / N << endl << endl;
}


int main()
{
    double hours[N] = {8, 6, 8, 4, 9};

    salary1(hours);
    salary2(hours);
    salary3(hours);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS