Help getting started

Can someone please help me get started on these problems? I have been looking through my book and i cannot seem to get anything going. Also, my compiler is telling me 'exp' is an invalid floating constant. I am trying to use 'exp' for 'e' but it is not letting me. Here are the problems i am having issues with:

1.) Using this formula, population=6.0e0.02[year-2000], write, compile, and run a C++ program to estimate the worldwide population in the year 2012. Verify the result of your program produces by calculation the answer manually. After verifying that your program is working correctly, use it to estimate the world's population in the years 2019 and 2025.

2.)Using this formula, remaining material = (original material)e-0.00012t, write, compile, and run a C++ program to determine the amount of radioactive material remaining after 1000 years, assuming an initial amount of 100 grams. Determine the amount of radioactive material remaining after 275 years, assuming an initial amount of 250 grams.

3.) The number of years it takes for an isotope of uranium to decay to one-half an original amount is given by this formula, where λ,, the decay constant (which is equal to the inverse of the mean lifetime), equals 0.00012:

half-life=ln(2)/λ

Using this formula, write, compile, and run a C++ program that calculates and displays the half-life of this uranium isotope. Determine the half-life of a uranium isotope with λ=0.00026.


It would be a huge help if someone could help me get started. Please and thank you!
Here is the first part that I did for question 1, but it would not work.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
double pop, year_1;
ofstream output ("C:result.dat");


while (year_1 == 2012)
{
pop=6.0exp(0.02(year_1-2000));
cout<<"enter year 2012: ";
cin>> year_1;
}
cout<<"\nThe estimated population in 2019 is "<<pop<<endl;

return 0;
}
There are three problems here.
1) Logic of population
2) Logic of radio active decay
3) How to write a C++ program

What exactly are you looking for? (I may sound like moron but giving you code for both won't teach you C++)
First, use [code ] [/code] tags. Second, C++ doesn't really "do" that whole implicit multiplication thing. Try:
pop=6.0*exp(0.02*(year_1 - 2000));

Second, you don't even need to loop, really, it's just a simple formula. Just put in the year and take out the estimated population.
Last edited on
I am just as confused as you are. What I typed above is all the information I know. I know for question one I am trying to find the estimated population in years 2012, 2019, and 2025.
More specifically for the program i started above, the only error it says i have is the exp being an invalid floating constant, which makes no sense to me because i was told by my professor to use 'exp' for 'e'
now it is saying that year_1 and pop arent initialized?
Well you should probably initialize them, then, shouldn't you? (Give them a value before you use them, even if it's 0. Until you give them a value they are just garbage numbers.)
Ok i got it. Thanks for your help!

#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
double pop,year_1;
ofstream output ("C:result.dat");
year_1= 2012;

// Problem 10

{
pop=6.0*exp(0.02*(year_1-2000));
cout<<"enter year 2012: ";
cin>> year_1;
}
cout<<"The estimated population (in billions) in year 2012 is "<<pop<<endl;

system ("PAUSE");
return 0;
}

Topic archived. No new replies allowed.