c++ Please
Write code to complete DoublePennies()'s base case. Sample
output for below program with inputs 1 and 10:
Note: If the submitted code has an infinite loop, the system
will stop running the code after a few seconds, and report "Program
end never reached." The system doesn't print the test case that
caused the reported message.
#include <iostream>
using namespace std;
// Returns number of pennies if pennies are doubled numDays
times
long long DoublePennies(long long numPennies, int numDays){
long long totalPennies;
/* Your solution goes here */
else {
totalPennies = DoublePennies((numPennies * 2),
numDays - 1);
}
return totalPennies;
}
// Program computes pennies if you have 1 penny today,
// 2 pennies after one day, 4 after two days, and so on
int main() {
long long startingPennies;
int userDays;
cin >> startingPennies;
cin >> userDays;
cout << "Number of pennies after " <<
userDays << " days: "
<< DoublePennies(startingPennies,
userDays) << endl;
return 0;
}
c++ Please Write code to complete DoublePennies()'s base case. Sample output for below program with inputs 1 and 10: Not
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
c++ Please Write code to complete DoublePennies()'s base case. Sample output for below program with inputs 1 and 10: Not
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!