// IC210 Class 9
// Can I save enough to buy the car I really want?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string junk, firstname, lastname;
char ch1, initial;
int amount, year, target;
double rate, Balance, tempBal,interest;
// Prompt for the name
cout << "input>";
cin >> firstname >> initial >> ch1 >> lastname;
// Prompt for the amount, rate and target
cout << "input>";
cin >> junk >> ch1>> amount >> junk >> junk >> junk >> rate >> ch1 >> junk
>> year >> junk >> junk >> ch1>> target >> ch1;
// Initialize variables
Balance = 0.0;
interest = rate/12/100;
// Calculate new balance
int i = 1;
while(i<=12*year)
{
tempBal = Balance + amount;
Balance = tempBal + tempBal * interest;
i++;
}
cout << "Ending balance = $" << Balance << '.' << ' ' << firstname;
// Can I buy what I want?
if (Balance < target)
cout << " the target is not met - pick a cheaper car!"<< endl;
else
cout << " the target is met - buy the car!" << endl;
return 0;
}