The First National Bank of Parkville recently opened up a new “So You Want to Be
ID: 3619540 • Letter: T
Question
The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows:• The bank doubles the customer’s balance every year until the customer’s balance reaches one million.
• The customer isn’t allowed to touch the money (no deposits or withdrawals) until the customer’s balance reaches one million.
• If the customer dies before becoming a millionaire, the bank keeps the customer’s balance.
• Note: Customers close to $1,000,000 tend to get “accidentally” run over in the bank’s parking lot.
Write a program that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
Sample session:
Enter starting balance: 10000
It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000
Explanation / Answer
#include <iostream>using namespace std;
int main()
{
double balance =0;
cout<<"Enter the initial balance: ";
cin>>balance;
cout<<endl;
int lakh =0, million = 0;
while( balance < 100000)
{
lakh++;
million++;
balance *=2;
}
while(balance <= 1000000)
{
million++;
balance *=2;
}
cout<<endl<<"It takes "<<lakh<<" years to reach $100,000"<<endl;
cout<<"It takes "<<million<<" years to reach $1000,000"<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.