This is a chaotic equation program I made, and it works fine- the problem is, there's something wrong with the Do { } while ( ) loop. If you run the program, and say, enter .0000000008 and then 60 (it doesn't matter, the first number has to be between 0 and 1), it'll display the output of the chaotic equation. Now, if you enter 1 to rerun the program, and try it again, it will continuously loop in the wrong area and I'm not sure what's wrong. Keep in mind, I'm a C++ newbie. Okey?
The code:
#include <iostream.h>
#include <stdio.h>
using namespace std; double x = (1/2); int con = 0; int le; char b; int rt = 1;
double equ (double left, double right);
int main()
{
do {
double v1 = 0, v2 = 0;
cout << "\nEnter the starting number (between 0.(0*100)1-0.((9*100)-1)).\n";
cout << "Then enter the number of iterations wanted.\n";
cout << "When the iterations are finished, press RETURN once to end.\n";
cout << ">"; cin >> x; cout << ">"; cin >> le;
if (le < 1) { le=1; };
if (le > 22255) { le=22255; };
do {
++con;
v1 = (2*x); v2 = (1-x);
x = equ(v1, v2);
cout << x << " ";
} while (con != le);
cout << "\n Enter 1 to rerun, 0 to exit\n";
cin >> rt;
} while (rt != 0);
return(0);
}
double equ(double left, double right)
{
double x = left*right;
return (x);
}
The code:
#include <iostream.h>
#include <stdio.h>
using namespace std; double x = (1/2); int con = 0; int le; char b; int rt = 1;
double equ (double left, double right);
int main()
{
do {
double v1 = 0, v2 = 0;
cout << "\nEnter the starting number (between 0.(0*100)1-0.((9*100)-1)).\n";
cout << "Then enter the number of iterations wanted.\n";
cout << "When the iterations are finished, press RETURN once to end.\n";
cout << ">"; cin >> x; cout << ">"; cin >> le;
if (le < 1) { le=1; };
if (le > 22255) { le=22255; };
do {
++con;
v1 = (2*x); v2 = (1-x);
x = equ(v1, v2);
cout << x << " ";
} while (con != le);
cout << "\n Enter 1 to rerun, 0 to exit\n";
cin >> rt;
} while (rt != 0);
return(0);
}
double equ(double left, double right)
{
double x = left*right;
return (x);
}