Thread Closed

Depreciation Program in C++ with arrays

 
Share Thread Thread Tools
Nov7-08, 10:55 PM   #1
 

Depreciation Program in C++ with arrays


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);
}

}
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Galaxies fed by funnels of fuel
>> The better to see you with: Scientists build record-setting metamaterial flat lens
>> Google eyes emerging markets networks
Nov8-08, 01:45 AM   #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;
dep_array[year-1]=depreciacion
val_array[year-1]=valor
...
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.
Nov8-08, 05:04 PM   #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...
Nov8-08, 07:05 PM   #4
 

Depreciation Program in C++ with arrays


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.
Thread Closed
Thread Tools


Similar Threads for: Depreciation Program in C++ with arrays
Thread Forum Replies
Need help soon with C++ program using pointers and arrays Programming & Comp Sci 6
running a Fortran 77 program in a C++ enviorment/program Programming & Comp Sci 2
Big arrays in gcc? Programming & Comp Sci 13
Astro simulation program problem - program bugs? Astrophysics 4
C++ Help, 2-D Arrays Engineering, Comp Sci, & Technology Homework 3