c++ - Do...While loop with probably if ... else statment inside with temporarily variables -



c++ - Do...While loop with probably if ... else statment inside with temporarily variables -

i asked, after giving me initial_population(7), growth_rate(1.2%), initial_year (2011), , formula link final population inital 1 next :

initial_population * exp ( (final_year - initial_year) * (rate/ 100.0))

for population entered, have made population grow year after year next forumla :

double pc(0.0); // pc = population entered while (pc <= initial_population) { cout << "how many billion (> 7) ? "; cin >> pc; }; int temp(year); { ++temp; cout << "population in " << temp << " : " << initial_population * exp ( (final_year - initial_year) * (rate/ 100.0)) << endl; } while ( pc > initial_population * exp ( (final_year - initial_year) * (rate/ 100.0)));

i create population growth_rate beingness divided 2 anytime initial population doubles , create show until population has reached entered population "pc". obviously, process must take longer when growth_rate wasn't divided , outcome should :

population in 2012 : 7.085 ; growth rate : 1.2 % population in 2013 : 7.17 ; growth rate : 1.2 % population in 2014 : 7.257 ; growth rate : 1.2 % population in 2015 : 7.344 ; growth rate : 1.2 % ... population in 2068 : 13.87 ; growth rate : 1.2 % population in 2069 : 14.04 ; growth rate : 0.6 % population in 2070 : 14.12 ; growth rate : 0.6 % ... population en 2195 : 29.02 ; growth rate : 0.3 %

all know in c++ yet until , while loops, of course of study if else statements.

is there anyonone can help me that, don't need have perfect answer, help on how start part. illustration how create statement when population doubles, etc.. ?

thanks lot.

save initial_population value, multiplied 2, in separate variable. check on each iteration if current_population (a variable made up, it's value should obvious) greater or equal other stored variable, multiply value 2 1 time again , split growth rate in half. this:

double population_doubled_check_val = initial_population * 2; double current_population; { ++temp; current_population = initial_population * exp ( (final_year - initial_year) * (rate/ 100.0)); cout << "population in " << temp << " : " << current_population << endl; if (current_population >= population_doubled_check_val) { population_doubled_check_val *= 2; rate /= 2; } } while ( current_population < pc );

i don't think copypasta of work, should give idea. on aside, it's helpful if provide full, minimum implementation necessary exemplify problem still compiles. no other reason answers faster. :)

c++ if-statement for-loop do-while

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -