# Homework Help: Depreciation Program in C++ with arrays

1. Nov 7, 2008

### Naldo6

Hi, i have did my program ccorrectly, but my profesor ask me to do with arrays and i dont know how to do thisprogram wuth arrays. Can anyone helps plz?... I talk with my profesor and see my prgram, and told me that it is all ok , but the only mistake is that i dont use arrays how the work is supossed to be done...

Little of the instructions....

This is a program to show the depreciation value of an item at some porcentage during the first 10 years. If the value of the item at the end of the year is less than 72% of the orignal value, must show "Value under Interested". You Must validate the entry data. Do it using arrays.

# include <stdio.h>
# include <math.h>

void main()
{

int year;
float valor,valorinicial,porciento,depreciacion;

printf("\nPrograma Para Determinar Depreciacion De Un Equipo\n\n");

do{
printf("Entre Valor Del Equipo:\n$"); scanf("\n%f",&valorinicial); }while(!(valorinicial>0)); do{ printf("\nEntre Nuevamente Valor Del Equipo:\n$");
scanf("\n%f",&valor);
}while(!(valorinicial==valor));

do{
printf("\nEntre El Porciento De Depreciacion:\n");
scanf("\n%f",&porciento);
}while(!(porciento>=0));

for(year=1;year<=10;year++)
{
depreciacion=valor*porciento/100;
valor=valor-valor*porciento/100;

if(valor>=.72*valorinicial)
printf("\nAl Year %i La Depreciacion= $%.2f y Valor Nuevo=$%.2f\n\n",year,depreciacion,valor);
else
printf("Al Year %i Valor Por Debajo De Lo Deseado\n\n",year);
}

}

2. Nov 8, 2008

### Nok1

The code is very simple, but what does your professor want you to use the arrays for?

Without your clarification, I'm going to guess that he wants you to store the information about each year in an array.

Code (Text):

int dep_array[10];
int val_array[10];

for(year=1;year<=10;year++) {
depreciacion=valor*porciento/100;
valor=valor-valor*porciento/100;
[b]dep_array[year-1]=depreciacion
val_array[year-1]=valor
...[/b]

The -1 is used in the index because you have to remember that arrays in C are 0-based, and you're dealing with "years" here. So somewhere later in your code, to get the proper index for a year, you'd have to take the year you wanted data from and subtract 1 from it.

I'm not sure if that answers your question though.

3. Nov 8, 2008

### Naldo6

Do you mean that?...

# include <stdio.h>
# include <math.h>

void main()
{
int dep_array[10];
int val_array[10];
int year;
float valor,valorinicial,porciento,depreciacion;

printf("\nPrograma Para Determinar Depreciacion De Un Equipo\n\n");

do{
printf("Entre Valor Del Equipo:\n$"); scanf("\n%f",&valorinicial); }while(!(valorinicial>0)); do{ printf("\nEntre Nuevamente Valor Del Equipo:\n$");
scanf("\n%f",&valor);
}while(!(valorinicial==valor));

do{
printf("\nEntre El Porciento De Depreciacion:\n");
scanf("\n%f",&porciento);
}while(!(porciento>=0));

for(year=1;year<=10;year++)
{
depreciacion=valor*porciento/100;
valor=valor-valor*porciento/100;

dep_array[year-1]=depreciacion;
val_array[year-1]=valor;

if(valor>=.72*valorinicial)
printf("\nAl Year %i La Depreciacion= $%.2f y Valor Nuevo=$%.2f\n\n",year,depreciacion,valor);
else
{
printf("\nAl Year %i La Depreciacion= $%.2f y Valor Nuevo=$%.2f\n\n",year,depreciacion,valor);
printf("\t Valor Por Debajo De Lo Deseado\n\n",year);
}
}

}

but how do i print the arrays?... because my printf are of the variables valores and depreciation, but how do i print with arrays?.... i thinks that that is what my profesor wants...

4. Nov 8, 2008

### Nok1

Yes, that's the general idea. If he wants you to print your arrays then you'd have to just call the index of the array you want to print. I'm not sure I'm understanding your question.

Read http://en.wikibooks.org/wiki/C_Programming/Arrays and see if that helps. Unless you clarify exactly what you need I'm not sure to further assist you.