The purpose of this assignment is to assess if you can create a program that uses recursion.

Directions

The file must be called unit2Prog.cpp

Program Definition

1.Create program definition for sumDigits Function. Function will receive and return an integer.

Main Method

1.Ask for input for numerous non-negative integers.

2.Using pass-by-reference, pass integer received into recursive function called sumDigits.

3.Receive result back from sumDigits and output result to screen.

4.Include: system("PAUSE"); after your output to pause the screen. See example below.

sumDigits Function (Receives integer)

1.Recursively call sumDigits adding up the integers received.

2.Return result to main method for output.

3.If a single digit is received, just return it to the main method.

Ensure you include ALL .cpp file(s) and any associated, student-defined .h (header) files required to make your program compile and run. The only files in the dropbox should be .cpp and .h files. Do not turn in .zip, .exe, .rar, etc files.

Example output of your program

Run 1:
Enter a nonnegative integer: 23
The sum of the digits of 23 is 5
Run 2:
Enter a nonnegative integer: 1234
The sum of the digits of 1234 is 10
Run 3:
Enter a nonnegative integer: 90513
The sum of the digits of 90513 is 18
Run 4:
Enter a nonnegative integer: 2147483647
The sum of the digits of 2147483647 is 46
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.