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

#include <stdio.h> main () { int numSalaries=0, counter=0, salary[100], salarySu

ID: 3624619 • Letter: #

Question

#include <stdio.h>

main ()
{
int numSalaries=0, counter=0, salary[100], salarySum=0, averageSalary=0;


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


printf ( "First,enter the number of salaries to process: " ); /* User is prompted to enter number of salaries*/
scanf ( "%i", &numSalaries );
fflush ( stdin );


while ( numSalaries<2 )

{
printf ( " You must use at least two salaries. " ); /* If entered less than 2, user will be prompted to re-enter*/
printf ( "Enter the number of salaries to process: " );
scanf ( "%i", &numSalaries );
fflush ( stdin );
}

printf ( " Now enter the %i salaries to be averaged. ", numSalaries );

while ( numSalaries>2 && counter<numSalaries )
{

counter++;
printf( " Enter Salary #%i: ", counter ); /* User will be prompted to enter corresponding number of salaries*/
scanf ( "%i", &salary[counter] );
fflush ( stdin );

salarySum=salary[counter]+salarySum;

if ( salary[counter]<0 )

{
printf ( " *** Invalid entry. Salary must be positive. *** " ); /* If negative amount is entered, message will be displayed and will be prompted to re-enter*/
printf( "Enter Salary #%i: ", counter );
scanf ( "%i", &salary[counter] );
fflush ( stdin );
}


}

averageSalary=salarySum/counter; /* Ouputs salary average */
printf ( " The average of the %i salaries entered is $%i.00 ", numSalaries, averageSalary );

if ( averageSalary < 999.99 )
printf ("Your salaries are low, how about a raise.");

if ( averageSalary >=1000 && averageSalary <1999.99 )
printf ( "Your salaries are very generous." );

if ( averageSalary > 2000 )
printf ( "Your salaries are very high." );

printf ( " " );

Explanation / Answer

// u are not supposed to take if conditon u have to take while loop.

// i have updated your modification in red colour

// compile and run using DEV C++.... ENJOY CHEERS :)

#include <stdio.h>
#include <conio.h>
int main ()
{
int numSalaries=0, counter=0, salary[100], salarySum=0, averageSalary=0;


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


printf ( "First,enter the number of salaries to process: " ); /* User is prompted to enter number of salaries*/
scanf ( "%i", &numSalaries );
fflush ( stdin );


while ( numSalaries<2 )

{
printf ( " You must use at least two salaries. " ); /* If entered less than 2, user will be prompted to re-enter*/
printf ( "Enter the number of salaries to process: " );
scanf ( "%i", &numSalaries );
fflush ( stdin );
}

printf ( " Now enter the %i salaries to be averaged. ", numSalaries );

while ( numSalaries>2 && counter<numSalaries )
{

counter++;
printf( " Enter Salary #%i: ", counter ); /* User will be prompted to enter corresponding number of salaries*/
scanf ( "%i", &salary[counter] );
while( salary[counter]<0 )

{
printf ( " *** Invalid entry. Salary must be positive. *** " ); /* If negative amount is entered, message will be displayed and will be prompted to re-enter*/
printf( "Enter Salary #%i: ", counter );
scanf ( "%i", &salary[counter] );
fflush ( stdin );
}

salarySum=salary[counter]+salarySum;




}

averageSalary=salarySum/counter; /* Ouputs salary average */
printf ( " The average of the %i salaries entered is $%i.00 ", numSalaries, averageSalary );

if ( averageSalary < 999.99 )
printf ("Your salaries are low, how about a raise.");

if ( averageSalary >=1000 && averageSalary <1999.99 )
printf ( "Your salaries are very generous." );

if ( averageSalary > 2000 )
printf ( "Your salaries are very high." );

printf ( " " );

getch();
return 0;
}