Trying to Create program definition for sumDigits Function. Function will receive and return an integer.
Main Method
Ask for input for numerous non-negative integers.
Using pass-by-reference, pass integer received into recursive function called sumDigits.
Receive result back from sumDigits and output result to screen.
Include: system("PAUSE"); after your output to pause the screen.
See example below.
sumDigits Function (Receives integer)
Recursively call sumDigits adding up the integers received.
Return result to main method for output.
If a single digit is received, just return it to the main method.
Ensure you include ALL files required to make your program compile and run. I would like to see your .cpp file and the .exe file that is inside your debug directory.
Upload your page to the Dropbox.
NOTE: Complete your activity and submit it to the Dropbox by clicking on the Dropbox tab at the top of the course frame and choosing the correct Weekly Activity.
If needed, click on the Help button above for more information on Course Tools/Using the Dropbox.
Total Possible Points
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// this is what I got so far...
#include <iostream>
using namespace std;
// prototype
int sumDigits(const int first, const int last, const int array[], const int array_size);
int main()
{
assert(( first > 0) && ( first < array_size));
assert((last > 0 )&& (last < array_size));
if (first == last)
return (array[first]);
return (array[first] + sum(first + 1, last, array));
system("PAUSE")
}
|