1. 'Limit of terms:' works, and when it reaches 1 it should stop regardless of this but it continues.
2.When printing numbers, input number must also be printed first.
example out put
Number: 15
Limit of terms: 50
15
46
23
70
35
106
53
160
80
40
20
10
5
16
8
4
2
1
#include <iostream>
void hailstoneSequence(int);
int main()
{
int n{};
std::cout << "Starting Number: ";
std::cin >> n;
hailstoneSequence(n);
}
void hailstoneSequence(int n)
{
while (n != 1) // As long as the n value is not 1, keep looping. Stop when n is 1.
{
if (0 == n % 2)
{
n = n / 2;
}
else
{
n = (3 * n) + 1;
}
std::cout << n << std::endl;
}
}