Nov 26, 2011 at 5:21pm Nov 26, 2011 at 5:21pm UTC
If d > 1 you will get a NaN because log is not defined for negative values
Nov 26, 2011 at 5:40pm Nov 26, 2011 at 5:40pm UTC
I see the problem. d is the depreciation rate, expressed as a percentage, if you want to use it in the program, you HAVE to do d=d/100. This will convert the rate into decimal, and then use it in your program.
EDIT: Yeah, Peter87, you're right.. I made a typo... Thanks...
Last edited on Nov 26, 2011 at 7:44pm Nov 26, 2011 at 7:44pm UTC
Nov 26, 2011 at 6:24pm Nov 26, 2011 at 6:24pm UTC
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float S,C,d,n;
int i;
cout<<"Please insert original cost="<<"\n";
cin>>C;
cout<< "Please insert depreciation rate= "<<"\n";
cin>>d;
cout<<"Please insert book value= "<<"\n";
cin>>S;
d=d*(1/100);
n=(log (S)-log(C))/log(1-d);
cout<<"number of years="<<n;
do
{
float book_value;
for (i=1; i<=n; i++)
S=(C*(pow((1-d), n)));
}
while(i<n);
{
cout<<"\n"<<"The value of the book after"<<i<<" years is: "<<S;
}
}
y i couldn't get the number of value for the each year..
Last edited on Nov 27, 2011 at 6:09am Nov 27, 2011 at 6:09am UTC