Write code to complete DoublePennies()'s base case. Sample output for below program:Number of pennies after 10 days: 1024 Note: These activities may test code with different test values. This activity will perform three tests, with startingPennies = 1 and userDays = 10, then with startingPennies = 1 and userDays = 40, then with startingPennies = 1 and userDays = 1. #include <iostream>using namespace std; // Returns number of pennies if pennies are doubled numDays timeslong 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 onint main() {long long startingPennies;int userDays; startingPennies = 1;userDays = 10;cout << "Number of pennies after " << userDays << " days: "<< DoublePennies(startingPennies, userDays) << endl;return 0;} Please help me with this problem using c++.
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 program:Number of pennies after 10 days: 1024
Note: These activities may test code with different test values. This activity will perform three tests, with startingPennies = 1 and userDays = 10, then with startingPennies = 1 and userDays = 40, then with startingPennies = 1 and userDays = 1.
#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;
startingPennies = 1;
userDays = 10;
cout << "Number of pennies after " << userDays << " days: "
<< DoublePennies(startingPennies, userDays) << endl;
return 0;
}
Please help me with this problem using c++.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- Recommended textbooks for youDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag…Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education