Is the code below correct? My compiler says there are errors but i cant find any.
Code:
// depletion of CFC compounds
#include <iostream.h>
int main()
{
double numyears;
double half_life;
double amount;
double name;
const double limit = 0.01; // amount we want from what start with
cout <<"Enter half life of the element/compound:" ;
cin >>half_life;
std::cin.get();
amount = 1.0; // % of what we start with
numyears=0.0; //number of years we have waited
while (amount > limit) //the new concept here. see NOTE
{
numyears=numyears + half_life;
amount = amount*0.5;
}
cout <<"You would have to wait " <<numyears << " years" <<endl;
std::cin.get();
return 0;
}
//NOTE
//the new concept here. It means...while the amount >limit , it keeps looping.
//Stops only if the stuff in() is false
//the next line is the main meat of loop
//it means, DO number of years =numyears+halflife while numyears increases by 1.
// While that happens, the amount is halved