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.
// 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
longlong totalpop = 7209120128; // total estimated population as of 2014
longlong growthyear = 100927654; // estimated growth per year
longlong growthpercent = 1.39999961; //the percentage that the growth takes
longlong 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) longlong 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 longlong 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 )
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.