Ok, first, I'm going to rename all your variables because single letter names are HORRIBLE style. *Only* use one letter names for index or loop variables (usually, use i & j).
Also, what does your parameter to the function (a) do? It's completely unused.
This is, I believe, a corrected version of your code; the following code does what I think you're trying to do.
Code:
float sld (float a){
float balance,depPercent,deprecation;
int yearCount, currentYear; // yearcount must be an integer, so make it one.
printf("Please enter the account balance:\n");
scanf("%f",&balance);
printf("Please enter the percentage of depreciation:%\n");
scanf("%f",&depPercent);
printf("Please enter the Number of Years:\n");
scanf("%d",&yearCount);
deprecation = 0;
for (currentYear = 0; currentYear <= yearCount; currentYear ++){
//do the printing FIRST, because in year 0, we want to see 0 deprecation.
printf("YEAR DEPRECIATION CURRENT VALUE\n");
printf("%d %4.2f %4.2f\n",currentYear,deprecation,balance);
deprecation = balance * depPercent; // you should multiply, not divide?
//scanf("%3.2f",&h); (what in the WORLD are you trying to do here??
balance = balance - deprecation;
}
return 0; // what value do you want to return??
}
I made a few assumptions about how you want to handle the number of years. I assumed that you wanted to input the number of years, and that you wanted how much it had deprecated in that period of time. Year "0" is the initial value before any deprecation.
I ran the above code, and it looked like this:
Code:
Please enter the account balance:
1000
Please enter the percentage of depreciation:%
0.10
Please enter the Number of Years:
5
YEAR DEPRECIATION CURRENT VALUE
0 0.00 1000.00
YEAR DEPRECIATION CURRENT VALUE
1 100.00 900.00
YEAR DEPRECIATION CURRENT VALUE
2 90.00 810.00
YEAR DEPRECIATION CURRENT VALUE
3 81.00 729.00
YEAR DEPRECIATION CURRENT VALUE
4 72.90 656.10
YEAR DEPRECIATION CURRENT VALUE
5 65.61 590.49
I do believe this is the correct output -- here, you have 10% deprecation, with an initial value of $1000.
BTW, did you want people to input, say, a 10% deprecation as 10, or as .10? Right now, a 10% deprecation should be entered as .1, but you can change this by adding this line after you read the deprecation value in:
depPercent = depPercent / 100;