Concept explainers
Write code to complete DoublePennies()'s base case. Sample output for below
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 nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Compute: z = √x Y Ex: If the input is 4.0 3.0, then the output is: 1.0 #include #include #include using namespace std; int main() { double x; double y; double z; } cin >> X; cin >> y; /* Your code goes here */ cout << fixed <<<arrow_forward#include <stdio.h>int main(){int i, j, k=0;for (i=1; i<3; i++){for (j=1; j<3; j++){k = i+j;printf("Value of k is %d\n" ,k);}}printf("Value of k is %d\n",2*k);return 0;} how do you modify this code so k only prints even numbersarrow_forwardCode is in Pythonarrow_forwardIn python This assignment assess problem solving ability and the use of the modulo operator, functions, lists and nested loops. The Modulo (%) operator returns a remainder of the two numbers divided. e.g. 9 % 2 will yield a 1 because 9/2 = 4 and the remainder is 1. Write one program that will compute both the Least Common Multiple, and the Greatest Common Factor of two random numbers between 2 and 30. The program will display all factors and multiples of the two numbers. When displaying the multiples of the numbers, only display up to the first input times the second input. Use functions to compute the answers. Loop the program so that the user try again. create the loop so that hitting enter will continue. The example is below: Integer1: 12Integer2: 3 The Multiples of 3 are 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, The Multiples of 12 are 12, 24, 36, The lowest common Multiples is 12 The Factors of 3 are 1, 3, The Factors of 12 are 1, 2, 3, 4, 6, 12, The greatest…arrow_forwardMad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Complete the program to read the needed values from input, that the existing output statement(s) can use to output a short story. Ex: If the input is: Eric Chipotle 12 cars the output is: Eric went to Chipotle to buy 12 different types of cars. 367012.2549490.qx3zqy7 LAB 2.14.1: LAB: Mad Lib 0/10 ACTIVITY LabProgram.java Load default template... 1 import java.util.Scanner; 2 3 public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String firstName; String genericLocation; int wholeNumber; String pluralNoun; 4 6 7 8 9 10 11 /* Type your code here. */ 12 System.out.println(firstName + } 13 went to + genericlocation + to buy + wholeNumber + differei 14 15arrow_forwardX609: Magic Date A magic date is one when written in the following format, the month times the date equals the year e.g. 6/10/60. Write code that figures out if a user entered date is a magic date. The dates must be between 1 - 31, inclusive and the months between 1 - 12, inclusive. Let the user know whether they entered a magic date. If the input parameters are not valid, return false. Examples: magicDate(6, 10, 60) -> true magicDate(50, 12, 600) –> falsearrow_forwardPython only 1. Define printGrid Use def to define printGrid Use any kind of loop Within the definition of printGrid, use any kind of loop in at least one place. Use any kind of loop Within the loop within the definition of printGrid, use any kind of loop in at least one place. it should look like this when called ; printGrid(['abcd','efgh','ijkl']) Prints: a b c d e f g h i j k l 2. Define getColumns Use def to define getColumns Use any kind of loop Within the definition of getColumns, use any kind of loop in at least one place. Use a return statement Within the definition of getColumns, use return _ in at least one place. it should look like this when called ; getColumns(['abcd','efgh','ijkl']) Out[]: ['aei', 'bfj', 'cgk', 'dhl']arrow_forwardWhat value does function Joy return when called with a value of 4?int Joy (int Q){ if (Q <= 1) return 1; else return Q * Joy(Q-1);}arrow_forwardarrow_back_iosarrow_forward_ios
- Database 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:PEARSON
- C 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