***Please read instructions carefully*** Problem: Write a program in C that will
ID: 3768287 • Letter: #
Question
***Please read instructions carefully***
Problem: Write a program in C that will calculate the salary raise for employees that will use LOOPS (while, do while or for loops may be used)
if salary is between $0 < $30000 the rate is 7.0%
if salary is between $30000 <= $40000 the rate is 5.5%
if salary is more than $40000 the rate is 4.0%
Instructions Given:
1. Use the appropriate functions and pass parameters for this program. Include at least one function that uses the return statement (non-void) and at least one function that does NOT use the return statement (void).
2. Write a function using loops that allows user to input the salaries (as many as they want).
3. Write a function that calculates the raises, the new salaries (raise + salaries), the total of the original salaries, the total of raises and the total of all the new salaries with the raises.
4. Write a function to print the output formatted exactly like the following example
5. You may have more functions than the 3 listed above
6. You must use a Loops in the program- you may either use a while loop, do loop, or for loops. DO NOT USE structs, arrays, etc.
7. Do not include other header files other than stdio.h and stdlib.h
Thank you.
Salary Rate % Raise New Salary 0.00 25,000.00 30,000.00 35,000.00 40,000.00 40,001.00 45,000.00 $215,001.00 0.00 0.00 0.00 7.00 1,750.00 26,750.00 5.50 1,650.00 31,650.00 5.50 1,925.00 36,925.00 5.50 2,200.00 42,200.00 4.00 1,600.04 41,601.00 4.00 1,800.00 46,800.00 $10,925.04 $225,926.00 TotalExplanation / Answer
#include<stdio.h>
#include<stdlib.h>
double totalSalary=0, totalRaise=0, totalNewSalary=0;
double calcRate(double salary) {
if (salary < 30000)
return 7.0;
else if (salary <= 4000)
return 5.5;
else
return 4.0;
}
void total(double salary, double raise, double newSalary) {
totalSalary += salary;
totalRaise += raise;
totalNewSalary += newSalary;
}
double calcRaise(double salary, double rate) {
return salary*rate/100.0;
}
double calcNewSalary(double salary, double raise) {
return salary+raise;
}
void display(double salary, double rate, double raise, double newSalary) {
printf(" %.2lf %.2lf %.2lf %.2lf ", salary, rate, raise, newSalary);
}
int main() {
int n, i;
double salary, rate, raise, newSalary;
double *salaries;
printf("How many salaries do you want to enter: ");
scanf("%d", &n);
salaries = (double *)malloc(sizeof(double)*n);
for (i=0; i<n ;i++) {
printf("Enter %d salary: ", i+1);
scanf("%lf", &salaries[i]);
}
printf(" Salary Rate% Raise New Salary ");
for (i=0; i<n; i++) {
salary = salaries[i];
rate = calcRate(salary);
raise = calcRaise(salary, rate);
newSalary= calcNewSalary(salary, raise);
total(salary, raise, newSalary);
display(salary, rate, raise, newSalary);
}
printf("Total");
printf(" %.2lf %.2lf %.2lf ", totalSalary, totalRaise, totalNewSalary);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.