Question: Write a function that calculates a Shaffer number. A Shaffer number starts with 1, then each successive number is equal to double the current number,
Write a function that calculates a "Shaffer" number. A "Shaffer" number starts with 1, then each successive number is equal to double the current number, and then 3 added to that. So, the first few numbers are: 1 // Now double it, plus 3 5 // Now double it, plus 3 13 // etc. ALSO: display the numbers in rows of 5 numbers across, each 5 characters wide. You will need to set the width to 9 to make the outputs match. Run an empty program to see what the output looks like. The "main" is supplied; leave that alone. IMPORTANT! Your program must actually calculate the numbers. You can not store the answers in the program. So, for example, if the number 16381 exists anywhere in your program, this is a hard-coded result and you will get a zero on assignment */ // STUFF AT THE TOP // WRITE YOUR FUNCTION HERE // DO NOT CHANGE ANYTHING BELOW HERE
#include
int main() { int num; int shaf; cout << "Please enter a number: "; cin >> num; cout << num << endl; shaf = shaffer(num); cout << endl; cout << "Shaffer (" << num << ") is " << shaf << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
