Depreciation Program in C++ with arrays

In summary, the conversation revolved around a program that calculates the depreciation value of an item using arrays. The code provided uses a simple for loop and if/else statements to calculate and display the depreciation and new value for each year. The expert suggests storing this information in arrays and using the index to print the desired values. More information on using arrays in C can be found in the provided link.
  • #1
Naldo6
102
0
Hi, i have did my program ccorrectly, but my profesor ask me to do with arrays and i don't know how to do thisprogram wuth arrays. Can anyone helps please?... I talk with my profesor and see my prgram, and told me that it is all ok , but the only mistake is that i don't 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);
}

}
 
Physics news on Phys.org
  • #2
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:
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
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
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.
 

1. What is a depreciation program in C++?

A depreciation program in C++ is a computer program that helps calculate the decrease in the value of an asset over time. This value is known as depreciation and is calculated using various methods such as straight line, double declining balance, and sum-of-years digits.

2. How does a depreciation program in C++ work?

A depreciation program in C++ works by taking in the necessary inputs such as the initial cost, salvage value, and useful life of an asset. It then uses these inputs to calculate the depreciation amount for each year and outputs the results in a user-friendly format.

3. Are arrays used in a depreciation program in C++?

Yes, arrays are often used in a depreciation program in C++. An array is a data structure that allows the program to store and manipulate multiple values of the same data type. In a depreciation program, arrays can be used to store the depreciation amounts for each year and perform calculations on them.

4. How accurate is a depreciation program in C++?

The accuracy of a depreciation program in C++ depends on the inputs provided by the user and the method used for depreciation calculation. If the inputs are correct and the method is applied accurately, the program should provide accurate results. However, it is always recommended to double-check the results to ensure accuracy.

5. Can a depreciation program in C++ be used for tax purposes?

Yes, a depreciation program in C++ can be used for tax purposes. In fact, many businesses use such programs to calculate the depreciation of their assets for tax deductions. However, it is important to consult a tax professional to ensure that the program is using the correct method and inputs for tax purposes.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top