Question

In: Computer Science

C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get...

C++ programming interest using for loops.

I'm fairly new to C++ programming. I really don't get for loops, and wanted help with this question. How do I go about it?

1a.

Write a program to ask the user for the starting balance of their savings account, what interest rate they are earning, and how many years they are planning to keep the account open. To calculate the new balance, including compounded interest: use a for loop to loop through the number of years the user specifies (1, 2, 3, 4, … years) and each time through the loop update the account balance using the following formula:

balance = balance * (1 + interest rate / 100.0)   // this adds one year’s interest to the account
              balance = initialBalance * (1 + interest rate / 100.0) // this will only calculate one year’s interest no matter how
                                                                                                                   many times you repeat it.

1b.

Now write the code to show the user how much money they would have after ONE year, depending on the different interest rates. Ask the user for a minimum and maximum interest rate (e.g. 3.0 and 8.5 … note you may need to swap the values if the user enters them out of order). Use a for loop to loop through the possible interest rates at 0.5 increments (3.0, 3.5, 4.0, 4.5, … 8.5) and each time through the loop calculate the user’s account balance after one year at the specified interest rate:

                             balance = initialBalance * (1 + interest rate / 100.0) // this time you want the initial balance

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem.

are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer.

Thanks
===========================================================================

#include<iostream>
using namespace std;


int main(){
  
  
   double balance=0.0, interest_rate=0.0;
   int years;
   cout<<"Enter your starting balance: $"; cin>>balance;
   cout<<"Enter interest rate (in %): "; cin>>interest_rate;
   cout<<"Enter the number of years planning to keep your account open: ";
   cin>>years;
  
   // starting from year =1 upto years
   for(int year=1; year<=years; year++){
       // the below line will execute that many times
       // as the number of years given;
       // so if user enter 5 years, then the below line will execute
       // 5 times
       balance = balance*(1+interest_rate/100);
       // after all the above lines are executed
       // year will be incremented by 1 ; ie. year++
   }
  
   cout<<"\nAfter "<<years<<" your total balance will be $"<<balance<<endl;
  
  
}

===========================================================================

#include<iostream>
#include<iomanip>
using namespace std;


int main(){
  
  
   double min_rate, max_rate;
   double intialBalance;
  
   cout<<"Enter initial balance: "; cin>>intialBalance;
   cout<<"Enter minimum interest rate (%): "; cin>>min_rate;
   cout<<"Enter maximum interest rate (%): "; cin>>max_rate;
  
   // you may need to swap the values if the user enters them out of order).
   if(max_rate<min_rate){
       cout<<"Swapping the max and min as they are out of order\n\n";
       double temp_Rate = max_rate;
       max_rate=min_rate;
       min_rate=temp_Rate;
   }
  
   double temp_balance;
   cout<<fixed<<showpoint<<setprecision(2);
   for (double rate=min_rate; rate<=max_rate; rate=rate+0.5){
       temp_balance = intialBalance;
       temp_balance = temp_balance*(1+rate/100.0);
      
       cout<<"At interest Rate: "<<rate<<"%, after 1 year you will have $"<<temp_balance<<endl;
      
   }
  
}

thanks a lot : )


Related Solutions

I'm trying to make this C++ loan calculator but I can't get the program to output...
I'm trying to make this C++ loan calculator but I can't get the program to output what I need. For instance I know the formula is right and when I enter 100000 1.5 20 as my cin variables I should get 482.55 but I get 1543.31. What am I not seeing as the issue? Also this should cout only 2 decimal places right? I'm not allowed to alter the #include and add any fixed setprecision. This is what I have....
if I need to get the sum of 6 numbers, here is a C programming solution...
if I need to get the sum of 6 numbers, here is a C programming solution int getSum(int number1, int number2, int number3, int number4, int number5, int number6); and the function is: int SUM; sum = number1+number2+number3+number4+number5+number6; return SUM; this function is called in main, and the main looks like: int totalSum; totalSum=getSum(1,2,3,4,5,6); while(1); so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can...
please I don't really know how to start answering this question I really need to understand...
please I don't really know how to start answering this question I really need to understand it please show the work with a clear handwriting A collision in one dimension A mass m1 = 2 kg moving at v1i = 3 ms−1 collides with another mass m2 = 4 kg moving at v2i = −2 ms−1. After the collision the mass m1 moves at v1f = −3.66 ms−1. (a) Calculate the final velocity of the mass m2. (b) After the...
In lab we did a liquid-liquid extraction using a separatory funnel - but i don't really...
In lab we did a liquid-liquid extraction using a separatory funnel - but i don't really understand what was happening ( i just followed directions given) - now my lab report asks me to describe 1. the concept of liquid liquid extraction and how it works 2. Describe how adjusting the pH of the aqueous phase as a means of altering solublity properties of compounds is used in extractions?? can anyone help me understand these two questions above.
C programming Rewrite the following function using no loops, and only tail call recursion double question5...
C programming Rewrite the following function using no loops, and only tail call recursion double question5 (int in) { int i; int result; for (result = rand(), i = 0; i < in; i += 3) { result /= i; result += rand(); } return result; }
HI, I hope you are doing well. I really don't understand this question and don't know...
HI, I hope you are doing well. I really don't understand this question and don't know how to solve it at all because I am completely new to this c++ programming. can you please explain each line of code with long and clear comments? please think of me as someone who doesn't know to code at all. and I want this code to be written in c++ thank you very much and I will make sure to leave thumbs up....
I need a C++ program using while loops that counts the number of characters in a...
I need a C++ program using while loops that counts the number of characters in a sentence. The user inputs a sentence and then terminates the input with either '.' or '!'. And then it needs to count and display the number of a's, e's, i's, o's, u's, and consonants. The program should read both lower and upper case. They don't want us using switch statements or string operators, and want us to us if else if statements. I have...
Well, I'm Lillian, and I'm here because I was in a really significant car accident about...
Well, I'm Lillian, and I'm here because I was in a really significant car accident about nine months ago and a couple weeks. And I guess, well, I used to really be in control of everything. I was really good at being kind of a lynch pin of my family and being able to make sure everybody got to where they needed to be. I was able to support people emotionally and get them to where they needed to be,...
Can someone explain how to get the answers step by step? I'm really confused by this...
Can someone explain how to get the answers step by step? I'm really confused by this stats question and I really need it "dummied down." A researcher has gathered information from a random sample of 178 households. For each of the following variables, construct confidence intervals to estimate the population mean. Use the 90% level. A. An average of 2.3 people resides in each household. Standard devisfikn is 0.35 B. There was an average of 2.1 television sets (s= 0.10)...
Introduction: One of the advantages of using Loops is to reduce the amount of programming effort...
Introduction: One of the advantages of using Loops is to reduce the amount of programming effort especially when repeating the code is required. To demonstrate this advantages, the code below shows the PasswordGeneration class. The purpose of this program is to generate an ad hoc 12 letters long password upon a selection of a character from a string that contains a pool of letters. /*simple Java program that generate a 12 characters long passwords * author : Dr. Modafar Ati...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT