Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program should ask the user for an integer, which will be the starting heigh

ID: 3755557 • Letter: T

Question

The program should ask the user for an integer, which will be the starting height of the hailstone. Based on the current value of the height, the program will repeatedly do the following: • If the current height is 1 (or 0), quit the program • If the current height is even, cut it in half (divide by 2) • If the current height is odd, multiply it by 3, then add 1 The program will keep updating the number, following the above rules, until the number is 1. It should print out the height of the hailstone at each step, including at the end. Once the hailstone is at height 1 (or 0), the program should end, and print out that the hailstone stopped. (HINT: Think carefully about the order in which the program checks each of the conditions, or it won’t perform correctly.) For example, given a starting value of 24, here are the numbers to output: 24 -> 12 -> 6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1

Explanation / Answer

#include using namespace std; int hailstone(int num) { if (num == 1) { return 0; } if (num%2==0) { num = num/2; } else { num = num*3 + 1; } return 1 + hailstone(num); } int main() { int n; cout