quick description:
f(n)=n/2 if even
f(n)=3*n+1 if odd
with given start value it can step back and forth between the two eqtns. Example: f(7)=22, f(22)=11, f(11)=34, f(34)=17
You enter two start values. first and last start value and the program should generate all values in between.
With a given max value the looping will stop
or stop when the given step value is reached.
It should output the value it's testing and the highest "f(n)" of that value.
I hope u guys can read my messy beginner code...something is wrong with the loop/loops cuz no values is printed out.
#include<iostream>
using namespace std;
int main()
{
int limit;
int steps;
int multiple = 0;
int start;
int start_last;
int highest = 0;
int a;
int b;
cout << "First start value: ";
cin >> start;
cout << "Last start value: ";
cin >> start_last;
cout << "Max value: ";
cin >> limit;
cout << "How many steps: ";
cin >> steps;
cout << endl << "start_value max_value"
<< endl << "_ _ _ _ _ _ _ _ _ _ _ _ " << endl;
for ( int i = 0; start_last >= start +i; ++i)
{
b = start +i; // <-- Somethings not right here on this line.
// I think...
while (b <= limit || multiple <= steps) // <- because b never gets
{ // in here and it gets stuck.
if (b%2 == 0) //even number
{
a = b/2;
}
else //else odd number
{
a = 3*b+1;
}
if (a > highest)
{
highest = a;
}
b = a;
++multiple;
}
cout << start +i << " " << highest << endl;
highest = 0; //reset highest
multiple = 0; //reset multiple
}
return 0;
}