### Hint Need For Assignment Due Tonight! How to pick out an item while in the loop and nothing else

Hello and thank you in advance for any help. I'm not asking for anyone to do it for me, but some direction would really help.

I have two questions
1. How do I get the numbers not to wrap in the console after outputting?
2. How to select when the the year that population doubles?

Problem:
Write a program that allows you to enter the current population, and the constant rate of increase over the years. Calculate and display the results over 75 years. Then show what year it doubled.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include #include using namespace std; int main() { int yearcounter = 1; double Currentpop; int Startingpop; double Populationgrowth; double Populationtotal; int Doublepop; int Growthrate; //Enter starting population { cout << "Enter Current Population: "; //prompt for input cin >> Startingpop; } //Enter population growth rate { cout << "Enter Population Growth Rate: "; //prompt for intput cin >> Growthrate; } //titles { cout << "Year\t" "Population\t" "Population Change\t" "\n"; } //Making starting pop into current pop Currentpop = Startingpop; Doublepop = Startingpop*2; while (yearcounter <= 75) { Populationgrowth = (static_cast(Currentpop)*Growthrate); cout << yearcounter << "\t"<< static_cast (Currentpop)<(Populationgrowth) + (Currentpop); Currentpop = static_cast(Populationtotal); yearcounter = yearcounter + 1; //increment by 1 } { if (Doublepop >= Currentpop) cout << "The year it doubled is" <

added `static int thisisit;`.

 ``1234`` ``````if (Doublepop >= Currentpop) { thisisit = yearcounter; }``````

`cout << "The year it doubled is " << thisisit+1;`

Remove if statement following the loop. When I compiled it, I had to add +1 to thisisit. Not sure why. I didn't examine all of your code thoroughly.
Thanks for the step forward!

How do I get it from not putting "the year it doubled is" after each of the years and just at the end with the result?
I figured it out, but would still love how to get the numbers to format right without all the trailing zeros, but I'm going to go ahead and send it in as is.

Thank you again for the help!
Trailing zeroes? It's probably got to do with your "setprecision".
Topic archived. No new replies allowed.