1 answer

Dylan has grandparents who believe in "planning for the future" instead of giving toys for birthdays...

Question:

Dylan has grandparents who believe in "planning for the future" instead of giving toys for birthdays and Christmas. Each year from the time Dylan is one year old, the grandparents deposit $10 for each year of his age for both his birthday and Christmas ($10 for each the first year, $20 for each the second year, etc.). Not taking interest into account, how much money will be in Dylan's account at the end of the year in which he turns 21?

(For this problem, it's ok to assume that Dylan's birthday comes before Christmas.)

Write a program for the above scenario that uses a for loop to calculate the answer.

Write a program for the above scenario that uses a while loop to calculate the answer.

Write a program for the above scenario that uses a do...while loop to calculate the answer.


Answers

Code

Using for loop

#include<iostream>
using namespace std;

int main()
{
   int i, amount=0;

   //using for loop

   for (int i = 1; i <= 21; i++)
   {
       amount += (i * 10);
   }
   cout << "Using for loop" << endl;
   cout << "Dylan's account at the end of the 21 year: $" << amount << endl;

  

   system("pause");
   return 0;
}

output

- x I C:\Users\josee\source\repos\Dylans account after 21 year Debug\Dylans account after 21 year.exe Using for loop Dylanusing while loop

#include<iostream>
using namespace std;

int main()
{
   int i, amount = 0;
   //using while loop
   i = 1; amount = 0;
   while (i <= 21)
   {
       amount += (i * 10);
       i++;
   }

   cout << "\n\nUsing while loop" << endl;
   cout << "Dylan's account at the end of the 21 year: $" << amount << endl;


   system("pause");
   return 0;
}

I C:\Users\josee\source\repos\Dylans account after 21 year Debug\Dylans account after 21 year.exe - x Using while loop Dylausing fo while

#include<iostream>
using namespace std;

int main()
{
   int i, amount = 0;
  
   i = 1; amount = 0;
  

   //using do while
   do
   {
       amount += (i * 10);
       i++;
   } while (i <= 21);
   cout << "\n\nUsing do while loop" << endl;
   cout << "Dylan's account at the end of the 21 year: $" << amount << endl;
   system("pause");
   return 0;
}

output

I C:\Users\josee\source\repos\Dylans account after 21 year Debug\Dylans account after 21 year.exe - x Using do while loop DIf you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

.

Similar Solved Questions

1 answer
What is the method of reproduction in C. elegans?
what is the method of reproduction in C. elegans?...
1 answer
A company is testing a new medicine for migraine medication using 250 participants.  Each participant was directed...
A company is testing a new medicine for migraine medication using 250 participants.  Each participant was directed to take the medicine (either the new medication or a placebo) when the first symptom occurred and then to record whether the headache went away within 45 minutes or it persist...
1 answer
Jorge is willing and able to pay up to $25 for an authentic autograph of Michael...
Jorge is willing and able to pay up to $25 for an authentic autograph of Michael Jordan that he buys for $20. Melissa requires a minimum price of $16 before she will sell the autograph to Jorge. In this situation, the consumer's surplus is and the producer's surplus is _. $25... $16 $25... D...
1 answer
Standard Product Costs Deerfield Company manufactures product M in its factory. Production of M requires 2...
Standard Product Costs Deerfield Company manufactures product M in its factory. Production of M requires 2 pounds of material P, costing $4 per pound and 0.5 hour of direct labor costing, $10 per hour. The variable overhead rate is $8 per direct labor hour, and the fixed overhead rate is $12 per dir...
1 answer
What is Scattering. Explain using formulas, diagrams and what applications it can be used for
What is Scattering. Explain using formulas, diagrams and what applications it can be used for...
1 answer
Ideal Gas Law Possible Units Write the equation for the P- Ideal Gas Law Possible Units...
Ideal Gas Law Possible Units Write the equation for the P- Ideal Gas Law Possible Units Possible Units Possible Units Possible Units Possible Units Example #1 What volume will 5.6 moles of sulfur hexafluoride gas occupy if the temperature and pressure of the gas are 128°C and 9.4 atm? Example #2...
1 answer
Bob's Lottery Inc. has decided to offer winners a choice of $220,000 in 10 years or...
Bob's Lottery Inc. has decided to offer winners a choice of $220,000 in 10 years or some amount currently. Assume that Bob's Lottery Inc. earns a 12 percent after-tax rate of return. What amount should Bob's offer lottery winners currently, in order to be Indifferent between the two choi...
1 answer
What is the basic method for graphing a linear equation
What is the basic method for graphing a linear equation...
1 answer
HL Construction Co. plans to replace one of its manufacturing equipment for a newer more technology-advance...
HL Construction Co. plans to replace one of its manufacturing equipment for a newer more technology-advance one. The new equipment has a purchase price of $8,000 and will be depreciated as a 7-year class for MACRS. Installation costs for the new equipment are $200. It is estimated that this equipmen...
1 answer
Question 6 100 mL of 0.25 M NaNO3 solution is mixed with 150 mL of 0.5...
Question 6 100 mL of 0.25 M NaNO3 solution is mixed with 150 mL of 0.5 M NaNO3 solution. What is the molarity of the resulting mixture? 0.2 M 0.4 M 0.1 M 8.5 M...
1 answer
QUESTION 2 Find the Marginal Rate of Substitution (MRSxy) of a consumer with preferences described by...
QUESTION 2 Find the Marginal Rate of Substitution (MRSxy) of a consumer with preferences described by U(x, y) = ln(2x + y). c. MRSxy=0.5 MRSxy=2 MRSxy = ? MRSxy = 2x+y None of the above 1 QUESTION 3 A consumer has preferences represented by utility function U(x, y) = x+y. The initial prices are Px =...
1 answer
PROBLEM 5. TUNING A CIRCUIT: PRACTICAL RESONANCE. Consider a forced RLC circuit with L-1 (H), R-1...
PROBLEM 5. TUNING A CIRCUIT: PRACTICAL RESONANCE. Consider a forced RLC circuit with L-1 (H), R-10 (12) and C 丽0 (f). Suppose an alternating current supplies a electromotive force Et)100 coswt. The equation modeling the charge Q(t) on the capacitor is 650 Q"(t) 10Q650Q(t) 100 coswt. a. Is...
1 answer
Solve: x^2 - 3x < 4
Solve: x^2 - 3x < 4...
1 answer
Power Drive Corporation designs and produces a line of golf equipment and golf apparel. Power Drive...
Power Drive Corporation designs and produces a line of golf equipment and golf apparel. Power Drive has 100,000 shares of common stock outstanding as of the beginning of 2021. Power Drive has the following transactions affecting stockholders' equity in 2021. March 1 Issues 50,000 additional shar...
1 answer
One of the major differences between dementia and delirium is A. Dementia has a rapid development...
One of the major differences between dementia and delirium is A. Dementia has a rapid development while delirium has a grad ous development development while delirium hordaland n 6. Delirium has a long with progressive deterioration while dementia has a brief c. Orientation in delirium progressively...
1 answer
Flag question Marked out of 6.00 Question 1 dy The solution of the IVP = (ax+by+1)...
Flag question Marked out of 6.00 Question 1 dy The solution of the IVP = (ax+by+1) where a ER and b ERVO) is bi y0)=0, Select one a. (ax + by - 1)(1-x-1 b. (ax+by+1)(1+x)=1 clax+by + 1) (1 -bx=1 dax+by = 1 lox+by+1 (1 -bx) = 1 2 Olax+by+1)- 1-bx (x+by+ 1X1 - bx) = 3 (ax+by+ 1X1 -bx) = 1 Ne...
1 answer
A firm's production function is when $50 has been paid, and zero otherwise. The unit prices...
A firm's production function is when $50 has been paid, and zero otherwise. The unit prices of capital and labor are r = $27 and w = $4, respectively. This firm's long-run total cost function is: Score: 1 of 1 2. Suppose the capital input i...
1 answer
If hemoglobin saturation is kept above _______%, the PO2 can change a lot with minimal change...
If hemoglobin saturation is kept above _______%, the PO2 can change a lot with minimal change in saturation....
1 answer
Refer to the figure below. The site consists of 8 ft of sand overlying 4 ft...
Refer to the figure below. The site consists of 8 ft of sand overlying 4 ft of clay. The groundwater level is 4 ft below the ground surface. Given that a proposed footing for a building will be 10 ft by 10 ft at a depth of 2 ft below the ground surface and the load on the foundation is 800 kips, cal...