Hi, this is a small program to print out three lists of values. One is
a simple increment count the others are values from two equations. I've
run this without problems before but when I've put in the new equations
I sometimes get columns of -1.#IND. I think it might have something to
do with using a wrong type or not including some important library
file, but I'm not sure and google has been little help. Anyone know the
problem?
Thanks...
#include <iostream// for std::cout
#include <fstream>
#include <iomanip>
using namespace std;
void choice();
double xnext, ynext, i;
double step = 0.0001;
double x = 10;
double r = 1.00;
double k = 5000.;
double d = .001;
double y = 5.;
double p = .5;
double a = .001;
double count = 0;
double count2 = 0;
double count3 = 0;
int main()
{
int vart;
cout << "1. x=" << x << endl << "2. r=" << r << endl << "3. k=" << k
<< endl << "4. d=" << d << endl;
cout << "5. y=" << y << endl << "6. p=" << p << endl << "7. a=" << a
<< endl<< "8. step=" << step << endl;
cout << "Do you want to change something? 1= yes 2 = no" << endl;
cin >vart;
if (vart == 1)
{
while (vart == 1)
{
choice();
cout << "1. x=" << x << endl << "2. r=" << r << endl << "3. k=" << k
<< endl << "4. d=" << d << endl;
cout << "5. y=" << y << endl << "6. p=" << p << endl << "7. a=" << a
<< endl<< "8. step=" << step << endl;
cout << "Do you want to change something?" << endl;
cin >vart;
}
}
ofstream dataout;
dataout.open("res.dat", ios::out);
for (i = 1; i <= 500000; i++)
{
count = count + 1;
count2 = count2 + 1;
count3 = count3 + 1;
if (count2 == 1000)
{
cout << step*i << std::endl;
count2 = 0;
}
xnext = (r*x*(1-x/k))-(d*x)-(p*x*y);
ynext = (p*x*y)-(a*y);
x = xnext;
y = ynext;
if (count == 100)
{
dataout.precision(10);
dataout << i*step << " " << x << " " << y <<
std::endl;
count = 0;
}
}
dataout.close();
return 0;
}
void choice()
{
int choice;
cout<< "what do you wish to change?" << endl;
cin >choice;
switch (choice)
{
case 1:
cin >x;
break;
case 2:
cin >r;
break;
case 3:
cin >k;
break;
case 4:
cin >d;
break;
case 5:
cin >y;
break;
case 6:
cin >p;
break;
case 7:
cin >a;
break;
case 8:
cin >step;
break;
default:
cout << "value of x unknown" << endl;
}
}