program is not working

Nov 3, 2010 at 11:54pm
Hi, I am very new to C++ and I my program is not working and I can't see why.
Here is my code, basically I am trying to find out if I invest a certain amount of money at an interest rate, how long will it take to buy a car which has a certain depreciation rate. Any help would be extremely appreciated.
Thanks!

#include <iostream>
using namespace std;
int main()
{


int Invest;
int InterestRate;
int CarPrice;
int Depreciation;
int InvestGrow;
int CarDecrease;
int Year = 0;


cout << "Please enter the amount of money you have to invest (in dollars):" << endl;
cin >> Invest;

cout << "Please enter the interest rate earned on the invested amount (in percent):" << endl;
cin >> InterestRate;

cout << "Please enter the current value of your dream car (in dollars): " << endl;
cin >> CarPrice;

cout << "Please enter the depreciation rate for the car (in percent):" << endl;
cin >> CarPrice;


//While loop that runs 5 times - from 1 to 5


while (InvestGrow <= CarDecrease)
{
Year = Year + 1;
InvestGrow = (Invest + (Invest * (InterestRate/100)));
CarDecrease = (CarPrice - (CarPrice *(Depreciation/100)));
//Text output
cout << "At the end of year " << Year << " you have $" << InvestGrow << "and the car now costs $" << CarDecrease << "." << endl;


}

return 0;
}
Nov 4, 2010 at 12:08am
You are declaring all your variables as integers. e. g. 0, 1, 2, 3....
You need to declare them as float. e.g. 5.45 or 0.08.

Also, you are using CarPrice for the depreciation instead of Depreciation for the input.

Nov 4, 2010 at 12:17am
I went through every section in this tutorial (http://www.cplusplus.com/doc/tutorial/), manually typing all the examples in CodeBlocks (
http://www.codeblocks.org/), and it helped me understand c++ much better.
Nov 4, 2010 at 12:17am
Thank you so much!!
Topic archived. No new replies allowed.