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

Rewrite the program below using a looping statement. You may use either a while

ID: 3694360 • Letter: R

Question

Rewrite the program below using a looping statement. You may use either a while loop, do loop, or for loop. Please include a brief statement in a comment in your program stating the assumptions you made to pick your looping statement. That is, if the loop is deterministic or inderministic and if the loop is entrance-controlled or exit-controlled.

#define _CRT_SECURE_NO_WARNINGS  
#include<stdio.h>
#include<stdlib.h>      

void load(float *cry, char *name, char *department)
{
  
   fflush(stdin);
   printf(" Enter name for an employee ");
   gets(name);
   printf(" Enter department for the employee ");
   gets(department);
   printf(" Enter Current Yearly Income for the employee $");
   scanf("%f", &(*cry));
}

float findrp(float cry, float *rp)
{
   if((cry) <= 70000)
       return *rp = 8.5;
   if((cry) >= 70000.01 && (cry) <= 80000)
       return *rp = 7.2;
   if((cry) >= 80000.01 && (cry) <= 90000)
       return *rp = 5.9;
   if((cry) >= 90000.01)
       return *rp = 5.1;
}

void calc(char *name, char *department, float cry, float rp, float *npa, float *ra)
{
   *ra = cry * rp / 100;
   *npa = cry + *ra;
   printf(" Name: %s", name);
   printf(" Department: %s", department);
   printf(" Current Yearly Income: $%0.2f", cry);
   printf(" Raise percentage: %0.2f", rp);
   printf(" Raise amount: $%0.2f", *ra);
   printf(" New pay amount: $%0.2f ", *npa);

}

void totals(float cry, float ra, float *totalcry, float *totalnpa, float *totalra)
{
   *totalcry += cry;
   *totalra += ra;
   *totalnpa = *totalcry + *totalra;
}

void printTotalInfo(float totalcry, float totalra, float totalnpa)
{
   printf(" The total of the current yearly incomes is $%0.2f ", totalcry);
   printf(" The total of the raise amounts is $%0.2f ", totalra);
   printf(" The total of the new pay amounts is $%0.2f ", totalnpa);
}

void main()
{
   char name[16];
   char department[10];
   float cry, rp, npa, ra;
   float totalcry = 0, totalra = 0, totalnpa;

   load(&cry, name, department);
   rp = findrp(cry, &rp);
   calc(name, department, cry, rp, &npa, &ra);
   totals(cry, ra, &totalcry, &totalnpa, &totalra);

   load(&cry, name, department);
   rp = findrp(cry, &rp);
   calc(name, department, cry, rp, &npa, &ra);
   totals(cry, ra, &totalcry, &totalnpa, &totalra);

   load(&cry, name, department);
   rp = findrp(cry, &rp);
   calc(name, department, cry, rp, &npa, &ra);
   totals(cry, ra, &totalcry, &totalnpa, &totalra);

   load(&cry, name, department);
   rp = findrp(cry, &rp);
   calc(name, department, cry, rp, &npa, &ra);
   totals(cry, ra, &totalcry, &totalnpa, &totalra);

   load(&cry, name, department);
   rp = findrp(cry, &rp);
   calc(name, department, cry, rp, &npa, &ra);
   totals(cry, ra, &totalcry, &totalnpa, &totalra);


   printTotalInfo(totalcry, totalra, totalnpa);

   system("PAUSE");
}

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
void load(float *cry, char *name, char *department)
{

fflush(stdin);
printf(" Enter name for an employee ");
fflush(stdin);
gets(name);
printf(" Enter department for the employee ");
gets(department);
printf(" Enter Current Yearly Income for the employee $");
scanf("%f", &(*cry));
}
float findrp(float cry, float *rp)
{
if((cry) <= 70000)
return *rp = 8.5;
if((cry) >= 70000.01 && (cry) <= 80000)
return *rp = 7.2;
if((cry) >= 80000.01 && (cry) <= 90000)
return *rp = 5.9;
if((cry) >= 90000.01)
return *rp = 5.1;
}
void calc(char *name, char *department, float cry, float rp, float *npa, float *ra)
{
*ra = cry * rp / 100;
*npa = cry + *ra;
printf(" Name: %s", name);
printf(" Department: %s", department);
printf(" Current Yearly Income: $%0.2f", cry);
printf(" Raise percentage: %0.2f", rp);
printf(" Raise amount: $%0.2f", *ra);
printf(" New pay amount: $%0.2f ", *npa);
}

void totals(float cry, float ra, float *totalcry, float *totalnpa, float *totalra)
{
*totalcry += cry;
*totalra += ra;
*totalnpa = *totalcry + *totalra;
}
void printTotalInfo(float totalcry, float totalra, float totalnpa)
{
printf(" The total of the current yearly incomes is $%0.2f ", totalcry);
printf(" The total of the raise amounts is $%0.2f ", totalra);
printf(" The total of the new pay amounts is $%0.2f ", totalnpa);
}
void main()
{
char name[16];
char department[10];
float cry, rp, npa, ra;
float totalcry = 0, totalra = 0, totalnpa;
//This loop will run 5 times, hence it is deterministic.
//For loop is entry controlled loop.
for(i = 0;i<5;i++){
load(&cry, name, department);
rp = findrp(cry, &rp);
calc(name, department, cry, rp, &npa, &ra);
totals(cry, ra, &totalcry, &totalnpa, &totalra);
}
printTotalInfo(totalcry, totalra, totalnpa);
system("PAUSE");
}

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