Simple question

Pages: 12
If d > 1 you will get a NaN because log is not defined for negative values
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
You mean d=d/100 right?

#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
Topic archived. No new replies allowed.
Pages: 12