# Need a second set of eyes.

Discussion in 'OT Technology' started by Disguy, Dec 5, 2009.

1. ### DisguyBatman > Moon KnightOT Supporter

Joined:
Oct 26, 2004
Messages:
1,062
1
Turns out it was a typo.

I'm doing this simple project to teach myself c++ and I can't figure out where I'm doing something wrong. Everything works technically but for some reason I'm getting an incorrect answer.

Its an interest calculator. Interest is paid annually.

Get deposit, get rate, calc the amounts for year 1, 2 and 3.

I enter in 100 for the amount, interest rate 1 (which changes to .01%).

I get 1101, 2102.01, 3103.03 for the years.

Somehow the program is adding 1000 to the amount each year. I don't see where I made a mistake.

Maybe I'm tired or whatever but I don't see it.

Code:
{
int deposit;
double rate;
double year1 =0 , year2 =0 , year3 =0;
int good =1;

do
{

cout << "Enter deposit amount:" ;
cin >> deposit;
cout << "\nEnter Annual Interest Rate: ";
cin >> rate;

cout << deposit;
cout << " ";
cout << rate;
cout << " ";
cout << year1;
cout << " ";
cout << year2;
cout << " ";
cout << year3;

cout << "\n ";
rate = 1+(rate/100);
cout << rate;
rate = rate;
cout << " ";
cout << rate;
year1 = deposit*rate;
year2 = year1*rate;
year3 = year2*rate;

cout << "\nBalence after Year 1";
cout << year1;
cout << "\nBalence after Year 2";
cout << year2;
cout << "\nBalence after Year 3";
cout << year3;
cout << "\n";

cout << "Good?";

cin >> good;
} while (good == 1);

Last edited: Dec 5, 2009
2. ### White StormyTake that, subspace!

Joined:
Sep 17, 2002
Messages:
85,552
84
Location:
Sparkopolis
Code:
cout << rate;
rate = rate;
cout << " ";
cout << rate;

what is that supposed to be doing..

3. ### DisguyBatman > Moon KnightOT Supporter

Joined:
Oct 26, 2004
Messages:
1,062
1
I was printing to the screen to see if where the error occurs. I had something else there before but took it out.

Joined:
Sep 17, 2002
Messages:
85,552
84
Location:
Sparkopolis
hahahahhaa

5. ### White StormyTake that, subspace!

Joined:
Sep 17, 2002
Messages:
85,552
84
Location:
Sparkopolis
I think I figured it out

6. ### White StormyTake that, subspace!

Joined:
Sep 17, 2002
Messages:
85,552
84
Location:
Sparkopolis
the calculated numbers are fine. you're reading the 1, 2, and 3 from this

Code:
cout << "\nBalence after Year [color=red]1[/color]";
cout << year1;
cout << "\nBalence after Year [color=red]2[/color]";
cout << year2;
cout << "\nBalence after Year [color=red]3[/color]";
cout << year3;

Joined:
Mar 14, 2000
Messages:
14,519
1
Location:

8. ### DisguyBatman > Moon KnightOT Supporter

Joined:
Oct 26, 2004
Messages:
1,062
1
that's not even funny... I missed a goddamn space.

9. ### deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,712
0
Actually it's incredibly funny.

Don't worry, you're only the billionth programmer to fuck up on something simple like this. It's always the tiny bugs that are hard to catch.

10. ### HYNew Member

Joined:
Dec 10, 2006
Messages:
57
0
your logic is right, you must not be running what you are compiling.
Code:
#include <iostream>
using namespace std;
int main()
{
int deposit = 100;
double year1, year2, year3, rate =1;
rate = 1+(rate/100);
year1 = deposit*rate;
year2 = year1*rate;
year3 = year2*rate;
cout << "year1\t" << year1 << "\tYear2\t" << year2 << "\tyear3\t" << year3 << endl;
}

or
Code:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int deposit = 100;
double rate = 1;
rate = 1+(rate/100);
for(int year=1;year <= 3;year++)
cout << "Year " << year << ":\t" << deposit* pow(rate,year) << endl;
}

Joined:
Sep 17, 2002
Messages:
85,552