Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that calculates and prints the average of two or more salaries

ID: 3761230 • Letter: W

Question

Write a C program that calculates and prints the average of two or more salaries entered by the user. The program should first prompt the user to enter the number of salaries to process (make sure: at least 2 salaries must be entered by user! Give an appropriate polite error message of your choice.) . It should then prompt the user for each salary. As each salary is entered, the program should ensure that the salaries entered are in the salary range of zero and above. If the salary is not in that range, an error message should be displayed (as shown below), and the user should be re-prompted for a salary. Any bad salaries entered should not be included in the average calculation. Once all values are entered, the program should calculate and print the average of all of the positive values entered, rounded off to the nearest whole cent. At the end display a message for the appropriate salary average. This program will feature the if statement as well as programming techniques for data validation. I call it a trap loop. It traps the user into entering valid data. The dialog with the user could be as follows: Welcome to the Salary Analyzer. This program calculates the average of as many salaries you wish to enter. First, enter the number of salaries to process: 4 Now enter the 4 salaries to be averaged. Enter salary #1: 900.00 Enter salary #2: 800.00 Enter salary # 3: -200 *** Invalid entry. Salary must be positive. *** Enter salary #3: 2500.01 Enter salary #4: 540.00 The average of the 4 salaries entered is $1185.00 Your average salary is adequate.

So far I have:

/* ------------------------------------------------------------------------
Program file: currency.c
Author: Megan Predki
Email: Megan.predki@student.uml.edu
Date: October 21, 2015
Assignment: Program #5
Course #: 90.211.031
Objective: This program will allow the user to to make banking transactions including deposits and withdrawals, along with showing a bank statement for the user.

--------------------------------------------------------------------------- */

#include <stdio.h>

int main(void)

{

/* Declaring Variables */


int x;
float number_of_salaries[2], salaries [50], average;
float total_salaries = 0, average_salary = 0;

/* Welcome Message */

printf("Welcome to the Predki Salary Analyzer. This program calculates the average of as many salaries you wish to enter.");
  


/* Current balance */
     

printf ("First, enter the number of salaries to process:");
scanf ("%f",&number_of_salaries);
  

/* Display an error message if the balance is less than two. */
   

if (number_of_salaries < 2);

printf ("Error: There must be at least two salaries to process, please re-enter! ");
  
  


/* Start a loop to keep track of salaries */

        for (x = 1; x <= number_of_salaries; x++)
{

do

   {
/* Enter amount of salaries */

printf ("Enter the amount of salary #%i: ", x);
scanf ("%f",&salaries[x]);
  
  

/* Average of salaries */

average_salary = (float) salaries[50] / number_of_salaries;
printf (" The average of the salaries entered is $%.2f ", average_salary);

/*end for loop*/



  
  
   }

/* Ending Average of Salaries */

else if (average_salary >= 2000.00)
printf (" *** Your average salary is very generous. *** ", average_salary);

  
    else if (average_salary <= 1000.00 && average_salary <= 1999.99)
printf ("***Your average salary is adequate.*** ");


    else if (average_salary <= 999.99)
printf ("***Your average salary is low, the employees need a raise.*** ");





{


return 0;

}

}
/* end main */

but I am getting a few error messages including: invalid operands to binary /, parse error before 'else', and parse error at end of input.

Explanation / Answer

#include <stdio.h>

int main(void)

{

/* Declaring Variables */


int x;
float number_of_salaries, salaries [50], average;
float total_salaries = 0, average_salary = 0;

/* Welcome Message */

printf("Welcome to the Predki Salary Analyzer. This program calculates the average of as many salaries you wish to enter.");
  


/* Current balance */


printf ("First, enter the number of salaries to process:");
scanf ("%f",&number_of_salaries);
  

/* Display an error message if the balance is less than two. */


if (number_of_salaries < 2);

printf ("Error: There must be at least two salaries to process, please re-enter! ");
  
  

/* Start a loop to keep track of salaries */

for (x = 1; x <= number_of_salaries; x++)
{

  
  
/* Enter amount of salaries */

printf ("Enter the amount of salary #%i: ", x);
scanf ("%f",&salaries[x]);
  
  

/* Average of salaries */

average_salary = (float) salaries[50] / number_of_salaries;
printf (" The average of the salaries entered is $%.2f ", average_salary);

/*end for loop*/



  
  
}

/* Ending Average of Salaries */

if (average_salary >= 2000.00)
printf (" *** Your average salary is very generous. *** ", average_salary);
else if (average_salary <= 1000.00 && average_salary <= 1999.99)
printf ("***Your average salary is adequate.*** ");
else if (average_salary <= 999.99)
printf ("***Your average salary is low, the employees need a raise.*** ");





{


return 0;

}

}
/* end main */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote