How can I make this simple assignment more eloquent ?
Hey guys I'm new to this forum and I'd like to find out if someone out there can make the code I've written for this homework assignment more eloquent. I somehow feel that the code is just really poorly written and my main goal is to reduce the number of lines of code I have written while still providing the same functionality.
*THIS IS A HOMEWORK ASSIGNMENT*
The assignment states the following:
Write a C program to calculate salary raise for employees.
If salary is between 0 < 30000 rate is 7.0%
If salary is between 30000 <= 40000 the rate is 5.5%
If salary is greater than 40000 the rate is 4.0%
1. you are to use appropriate functions and pass parameters for this program. Please include at least one function that uses the return statement and at least one function that does not use the return statement.
2. Draw a structure chart that shows all the functions.
3. Write a function to allow user to inpu the salaries only.
4. Write a function to calculate the raises, the new salaries(raise+salary), total of the original salaries, the total of raises and the total of all the new salaries with the raises.
5. Write a function to print the output as a table with 10 rows and 5 columns. Column names are Total, Salary, Rate%, Raise, New Salary.
6. you may have more than the 3 functions mentioned in item 3, 4, 5.
7. DO NOT USE LOOPS.
Here's what I wrote:
Code:
#include <stdio.h>
#include <stdlib.h>
//function prototypes
void inputsalary(float *, float *, float *, float *, float *, float *, float *);//user input
//print
void print(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float st,
float r1, float r2, float r3, float r4, float r5, float r6, float r7,
float rs1, float rs2, float rs3, float rs4, float rs5, float rs6, float rs7,
float rst,
float ns1, float ns2, float ns3, float ns4, float ns5, float ns6, float ns7,
float nst);
//return total of all seven salaries
float total7(float s1, float s2, float s3, float s4, float s5, float s6, float s7);
//calculate rates for each salary
void rate7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float *, float *, float *, float *, float *, float *, float *);
//calculate raise for each salary
void raise7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float r1, float r2, float r3, float r4, float r5, float r6, float r7,
float *, float *, float *, float *, float *, float *, float *, float *);
void newsalary7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float rs1, float rs2, float rs3, float rs4, float rs5, float rs6, float rs7,
float *, float *, float *, float *, float *, float *, float *,
float *);
int main()
{
//variables
float s1, s2, s3, s4, s5, s6, s7; //Salaries 1 - 7
float st; //Salary total
float r1=0, r2=0, r3=0, r4=0, r5=0, r6=0, r7=0; //Rate% 1-7
float rs1=0, rs2=0, rs3=0, rs4=0, rs5=0, rs6=0, rs7=0; //Raise 1-7
float rst=0; //Raise total
float ns1=0, ns2=0, ns3=0, ns4=0, ns5=0, ns6=0, ns7=0; //New Salary 1-7
float nst=0; //New Salary total
//functions
inputsalary(&s1, &s2, &s3, &s4, &s5, &s6, &s7); //User input
st = total7(s1, s2, s3, s4, s5, s6, s7); //Calculate Salary total
rate7(s1, s2, s3, s4, s5, s6, s7, &r1, &r2, &r3, &r4, &r5, &r6, &r7); //Calculate rate for each salary 1-7
raise7(s1, s2, s3, s4, s5, s6, s7, // salaries 1-7
r1, r2, r3, r4, r5, r6, r7, //rates 1-7
&rs1, &rs2, &rs3, &rs4, &rs5, &rs6, &rs7, &rst ); //raises 1-7
newsalary7(s1, s2, s3, s4, s5, s6, s7, // salaries 1-7
rs1, rs2, rs3, rs4, rs5, rs6, rs7, // raises 1-7
&ns1, &ns2, &ns3, &ns4, &ns5, &ns6, &ns7, //new salaries 1-7
&nst); // New Salaries total
print(s1, s2, s3, s4, s5, s6, s7, //salaries 1-7
st, //salaries total
r1, r2, r3, r4, r5, r6, r7, //rate% 1-7
rs1, rs2, rs3, rs4, rs5, rs6, rs7, //Raise 1-7
rst, //Raise total
ns1, ns2, ns3, ns4, ns5, ns6, ns7, //New Salary 1-7
nst //New Salary total
); //Print output
system("PAUSE");
return 0;
}
//user input
void inputsalary(float *s1, float *s2, float *s3, float *s4, float *s5, float *s6, float *s7)
{
printf("Enter salary 1:");
scanf("%f", &(*s1));
printf("Enter salary 2:");
scanf("%f", &(*s2));
printf("Enter salary 3:");
scanf("%f", &(*s3));
printf("Enter salary 4:");
scanf("%f", &(*s4));
printf("Enter salary 5:");
scanf("%f", &(*s5));
printf("Enter salary 6:");
scanf("%f", &(*s6));
printf("Enter salary 7:");
scanf("%f", &(*s7));
}
//return salary total
float total7(float s1, float s2, float s3, float s4, float s5, float s6, float s7)
{
return s1 + s2 + s3 + s4 + s5 + s6 + s7;
}
//calculate rate for each salary
void rate7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float *r1, float *r2, float *r3, float *r4, float *r5, float *r6, float *r7)
{
//------------------------------- salary rate 1
if(s1 < 30000)
{
*r1 = 7.0;
}
if(s1 >= 30000 && s1 <= 40000)
{
*r1 = 5.5;
}
if(s1 > 40000)
{
*r1 = 4.0;
}
//------------------------------- salary rate 2
if(s2 < 30000)
{
*r2 = 7.0;
}
if(s2 >= 30000 && s2 <= 40000)
{
*r2 = 5.5;
}
if(s2 > 40000)
{
*r2 = 4.0;
}
//------------------------------- salary rate 3
if(s3 < 30000)
{
*r3 = 7.0;
}
if(s3 >= 30000 && s3 <= 40000)
{
*r3 = 5.5;
}
if(s3 > 40000)
{
*r3 = 4.0;
}
//------------------------------- salary rate 4
if(s4 < 30000)
{
*r4 = 7.0;
}
if(s4 >= 30000 && s4 <= 40000)
{
*r4 = 5.5;
}
if(s4 > 40000)
{
*r4 = 4.0;
}
//------------------------------- salary rate 5
if(s5 < 30000)
{
*r5 = 7.0;
}
if(s5 >= 30000 && s5 <= 40000)
{
*r5 = 5.5;
}
if(s5 > 40000)
{
*r5 = 4.0;
}
//------------------------------- salary rate 6
if(s6 < 30000)
{
*r6 = 7.0;
}
if(s6 >= 30000 && s6 <= 40000)
{
*r6 = 5.5;
}
if(s6 > 40000)
{
*r6 = 4.0;
}
//------------------------------- salary rate 7
if(s7 < 30000)
{
*r7 = 7.0;
}
if(s7 >= 30000 && s7 <= 40000)
{
*r7 = 5.5;
}
if(s7 > 40000)
{
*r7 = 4.0;
}
}
//calculate raise for each salary
void raise7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float r1, float r2, float r3, float r4, float r5, float r6, float r7,
float *rs1, float *rs2, float *rs3, float *rs4, float *rs5, float *rs6, float *rs7,
float *rst)
{
*rs1 = s1*r1/(float)100;
*rs2 = s2*r2/(float)100;
*rs3 = s3*r3/(float)100;
*rs4 = s4*r4/(float)100;
*rs5 = s5*r5/(float)100;
*rs6 = s6*r6/(float)100;
*rs7 = s7*r7/(float)100;
*rst = *rs1 + *rs2 + *rs3 + *rs4 + *rs5+ * rs6 + * rs7;
}
void newsalary7(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float rs1, float rs2, float rs3, float rs4, float rs5, float rs6, float rs7,
float *ns1, float *ns2, float *ns3, float *ns4, float *ns5, float *ns6, float *ns7,
float *nst)
{
*ns1 = s1+rs1;
*ns2 = s2+rs2;
*ns3 = s3+rs3;
*ns4 = s4+rs4;
*ns5 = s5+rs5;
*ns6 = s6+rs6;
*ns7 = s7+rs7;
*nst = *ns1 + *ns2 + *ns3 + *ns4 + *ns5 + *ns6 + *ns7;
}
//print output
void print(float s1, float s2, float s3, float s4, float s5, float s6, float s7,
float st,
float r1, float r2, float r3, float r4, float r5, float r6, float r7,
float rs1, float rs2, float rs3, float rs4, float rs5, float rs6, float rs7,
float rst,
float ns1, float ns2, float ns3, float ns4, float ns5, float ns6, float ns7,
float nst)
{
printf(" Calculation of Salary Rasies\n\n");
printf(" Salary Rate%% Raise New Salary \n");
printf(" \n");
printf(" %0.2f %0.2f %0.2f %0.2f \n", s1, r1, rs1, ns1);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s2, r2, rs2, ns2);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s3, r3, rs3, ns3);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s4, r4, rs4, ns4);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s5, r5, rs5, ns5);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s6, r6, rs6, ns6);
printf(" %0.2f %0.2f %0.2f %0.2f \n", s7, r7, rs7, ns7);
printf(" Total %0.2f %0.2f %0.2f \n", st, rst, nst);
}