c++ Please Write code to complete DoublePennies()'s base case. Sample output for below program with inputs 1 and 10: Not
Posted: Thu May 05, 2022 1:12 pm
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;
}
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;
}