Write code to complete DoublePennies()'s base case. Sample output for below program with inputs 1 and 10:Number of pennies after 10 days: 1024 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 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; } Only the your solution goes here can be changed, everything else cannot be edited.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Write code to complete DoublePennies()'s base case. Sample output for below
#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;
}
Only the your solution goes here can be changed, everything else cannot be edited.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps