Can't figure out what's going wrong in my loop...

For some reason my calculations are correct for this loop when the generations are less than the input amount for Jackalopes but when I enter a higher generation amount than the Jackalopes the calculation no longer works. Any help is appreciated, thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main()
{

  int jacks, gen, newpop;
  const int birth = jacks + .03;
  cout << "How many jackalopes do you have?\n";
  cin >> jacks;
  cout << "How many generations do you want to wait?\n";
  cin >> gen;

  int year = 0;

  newpop = jacks;

  do
  {
    newpop = newpop * 1.03;
    newpop = newpop - .01;
    year++;
  } while ( year < gen );


  cout << "If you start with " << jacks << " and you wait for\n" 
  << gen<< " generations, you'll end up with a total of " 
  << newpop<< " of them.";
  
  return 0;
}


How many jackalopes do you have?
200
How many generations do you want to wait?
1
If you start with 200 and you wait for
1 generations, you'll end up with a total of 205 of them.[aarev001@flanders ~]$ ./a.out
How many jackalopes do you have?
132
How many generations do you want to wait?
2
If you start with 132 and you wait for
2 generations, you'll end up with a total of 137 of them.[aarev001@flanders ~]$ ./a.out
How many jackalopes do you have?
40
How many generations do you want to wait?
100
If you start with 40 and you wait for
100 generations, you'll end up with a total of 40 of them.
Working with ints means you get round-down errors. Work with doubles until the last minute when you print out the result as an int.
Topic archived. No new replies allowed.