Depreciation Program in C++ with arrays

  • Context: Comp Sci 
  • Thread starter Thread starter Naldo6
  • Start date Start date
  • Tags Tags
    Arrays C++ Program
Click For Summary

Discussion Overview

The discussion revolves around implementing a depreciation program in C++ using arrays, as requested by a professor. The program aims to calculate the depreciation value of an item over ten years based on a specified percentage, while also validating input data.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • One participant expresses uncertainty about how to incorporate arrays into their existing program, which currently calculates depreciation without using them.
  • Another participant suggests that the professor likely wants the depreciation values and item values for each year stored in arrays.
  • A code snippet is provided by one participant to illustrate how to declare and use arrays for storing depreciation and item values.
  • Further, a participant seeks clarification on how to print the values stored in the arrays, indicating a lack of understanding of array indexing in C.
  • Another participant recommends consulting an external resource for more information on arrays, but does not provide specific guidance on printing the array contents.

Areas of Agreement / Disagreement

There is no consensus on the exact requirements of the professor regarding the use of arrays, and participants express varying levels of understanding about how to implement and print array values.

Contextual Notes

Participants have not fully clarified the professor's expectations, and there are unresolved questions about how to properly print the contents of the arrays.

Naldo6
Messages
102
Reaction score
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
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.
 
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...
 
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.
 

Similar threads

Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
9
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K