I am a 22 year old college gal currently enrolled in a c++ course, and we are on the topic of recursion. I understand how it works and have completed several other exercises on the professor has listed in the book, but this one has me stumped. Is there anyone out there that could help me out? I think I have 90% of it done. The question is in three parts, and its the last part I cannot seem to get:
part 3: Extend the function of exercise 5 so that it also outputs a running total as the numbers are printed out in revers order. For example the i/o dialog might be the following:
Enter Positive Number, 0 to End: 10
Total: 10
Enter Positive Number, 0 to End: 20
Total: 30
Enter Positive Number, 0 to End: 30
Total: 60
Enter Positive Number, 0 to End: 0
The function then outputs:
30 total: 30
20 total: 50
10 total: 60
It is the last total while the numbers are printed reversed that I just can't get.
I will paste in my "working" code below, omitting the cout portion that I can't figure out. I hope one of ya'll can help me, I've heard good things about this place.
void posInteger(int sum){
int number;
cout << "Enter Positive Number, 0 to end: ";
cin >> number;
sum = sum+number;
if(number <= 0){
return;
}
else{
cout << "Sum: " << sum << endl;
posInteger(sum);
cout << number << " Total: " << endl;
}
}