C++ Cin Problem!!!

When I run this program and call the function BacteriaVariables, the program stops running before inputing the variable. If I print the variable n afterwards it says it is set to zero.

#include <iostream>
#include <cmath>
using namespace std;

int k;
int n;
double population[11];

void BacteriaVariables ()
{
cout << "Please input growth factor (k) [0.0-1.0] : ";
cin >> k;
cout << "Please input initial population (N0) [1-1000] : ";
cin >> n;
}

void BacteriaGrowth()
{
for (int i=0; i<10; i++)
{
population[i]= n*exp(k*i);
}
}

void BacteriaPopulation ()
{
cout << "Time Population";
for (int i=0; i<10; i++)
{
cout << i << " " << population[i];
}
}

int main ()
{
BacteriaVariables();
return 0;
}
Your prompt for k says "[0.0-1.0]", but k is an int. It will not hold a factional number.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Topic archived. No new replies allowed.