C++ Hailstone Sequence
Musicrafter 10 Feb 2015 00:12
#include<iostream>
using namespace std;
int main(int o, int c)
{
cout<<"The Hailstone Sequence"<<endl;
for( ; ; )
{
cout<<"Pick any number. " <<endl;
cin>> o;
cin.ignore();
cout<<"Your number is: "<< o <<endl;
cout<<"The sequence generated will be displayed below."<<endl;
// Code to go through the "hailstone sequence"
c = 0;
while ((o/2 >= 1) and ((o * 3)+1 >= 1))
{
if (o % 2 == 0)
{
o = o/2;
cout<<" "<<o;
c = c+1;
if (c % 7 == 0)
{
cout<<""<<"\n";
}
if (o == 1)
break;
}
if (o % 2 != 0)
{
o = (o * 3)+1;
cout<<" "<<o;
c = c+1;
if (c % 7 == 0)
{
cout<<""<<"\n";
}
if (o == 1)
break;
}
}
cout<<endl<<"The sequence produced the following amount of numbers: "<<c<<endl;
system("pause");
}
}