problem with numbers

Hey all. Worlds worst programmer here again. My inquisitor.........er I mean my professor has an issue with my program. The basis of it is that I have to have three columns. One for the year, the other for the total population, and the last for the incrementing growth that adds to the total. I thought it was accurate, but he was complaining that the growth wasn't showing on the right side. I thought my math was okay.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 // Lab 2c, Tabular Formatting
// Programmer: Jesse Burns
// Editor(s) used: JNotePad
// Compiler(s) used: VC++ 2010 Express
// The necessary C++ file library
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <string>
using std::string;

#include <iomanip>
using std::setw;

#include <cstdlib>

int main()
{
  // Jesse Burns, Lab 2c.
  cout << "Lab 2c, Tabular Formatting\n";
  cout << "Programmer: Jesse Burns\n";
  cout << "Editor(s) used: JNotePad\n";
  cout << "Compiler(s) used: VC++ 2010 Express\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Compiled: " << __DATE__ << " at " << __TIME__ << endl << endl;

  //The variables needed to show initial year population and subsequent growth
  long long totalpop = 7209120128;  // total estimated population as of 2014
  long long growthyear = 100927654; // estimated growth per year
  long long growthpercent = 1.39999961; //the percentage that the growth takes
  long long growthyearpluspercent; //variable to hold the calculated percentage growth per year
  int loop = 1;
  int year = 2013;

  //The cout for header//
  cout << "World Population Growth estimate for next 75 years." << endl;
  cout << "-------------------------------------------------------------------"<<endl;
  cout << "Year----------------Predicted Growth-----------Growth for that year"<<endl;
  cout << "-------------------------------------------------------------------"<<endl;

  //A while loop to increment the year and population up to seventy five years.
  while (loop <= 75)
  {

  //The math needed for conversion per year and total population added per year.
  loop++;
  year++;
  growthyearpluspercent = growthpercent * growthyear;
  totalpop = totalpop + growthyearpluspercent;
  //The cout necessary to show that year to year growth.
  cout << year << setw(30) << totalpop << setw(30) << growthyearpluspercent <<endl;


Any suggestions on what I might be doing wrong as far as incrementing on the far right side? Thanks.
I am a bit confused are you increasing population by percentage or by a linear amount. Do you have a formula we can see? There are a few things I see wrong that stand out:

1) long long growthpercent = 1.39999961; you are trying to assign a double to an integer so it will be floored when converted to integer which would be equal to long long growthpercent = 1;

2) growthyearpluspercent = growthpercent * growthyear; this will not change no matter how many times you loop. It would be equal to:
gworthyearpluspercent = growthpercent; since we are multiplying by 1 but anyways it wouldn't change ever because growthpetcent and year never change.

Once again a formula would be helpful. For most populations the formula is
Pert
or
Final Population = Initial Population * egrowth rate (%) * time


or for a linear growth:
Final Population = Initial Population + ( time * growth rate(flat amount) )




*edit The formula you program is currently using is:

Final Population = 7209120128 + ( time(years) * 100927654 )
Last edited on
Oh. Well I was trying to increment the yearly value that the population would increase by and show that along with storing the final population growth on the same line as well. I don't understand why the population growth won't increment as the final population has in my program.
Topic archived. No new replies allowed.