c++ Please Write code to complete DoublePennies()'s base case. Sample output for below program with inputs 1 and 10: Not

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
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

Post by answerhappygod »

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;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply