Hi all, basically my assignment is to write a program to alter the salaries of n employees based on the following conditions: If the salary is less than 10,000 then give a 5% bonus etc. If its 10,000-20,000 then another set of changes to the salary are done, anything higher than 20,000 also receives its own changes.
As you can see, the size of the arrays that contain the values for salary and new salary are dependent on integer n, which is entered by the user. This format does not work on my compiler, as the program itself stops before printing the first line. However when I change s[n] to s[100], l[n] to l[100], the function works. I want to know why I cannot use the s[n] format, instead of just using a random number for the number of salaries/altered salaries after changes. Any help would be greatly appreciated, thank you.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n;
float s[n],l[n];
printf("Please enter the number of employees: ");
scanf("%d",&n);
for (i=0;i<n;i++)
printf("Please enter the salary: ");
scanf("%f",&s[i]);
if (s[i]<10,000)
{
l[i]=s[n]+(0.05*s[i]);
printf("Salary after changes: %f",l[i]);
}
else if ((s[n]>=10,000)&&(s[n]<20,000))
{
l[i]=s[i]-(0.03*s[i]);
l[i]=l[i]-(0.01*l[i]);
l[i]=l[i]+(.025*l[i]);
printf("Salary after changes: %f",l[i]);
}
else
{
l[i]=s[i]-(0.05*s[i]);
l[i]=l[i]-(0.02*l[i]);
l[i]=l[i]-(0.01*l[i]);
l[i]=l[i]+(0.08*l[i]);
printf("Salary after changes: %f",l[i]);
}
return 0;
}