Im having a hard time where to start with this assignment. Obviously I did the easy part now its time for the loop which i just dont get.

heres how the program will run
Enter the initial balance ===> 1000

Enter the number of months to cover: ===> 3
Enter the annual interest rate (decimal format; e.g., 5 not .05) ===> 10
Enter the amount deposited for month 1 ===> 500
Enter the amount withdrawn for month 1 ===> 400
Enter the amount deposited for month 2 ===> 600
Enter the amount withdrawn for month 2 ===> 700
Enter the amount deposited for month 3 ===> 800
Enter the amount withdrawn for month 3 ===> 900

Starting balance: \$ 1000.00
Total amount deposited: \$ 1900.00
Total amount withdrawn: \$ 2000.00
Total interest earned: \$ 25.64
Final balance: \$ 925.64

so far my code lol

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

int main()
{

int startbalance, months;
float rate;

cout <<"Enter the initial balance:";
cin >> startbalance;

cout <<"Enter the number of months to cover:";
cin >> months;

cout <<"Enter the annual interest rate (decimal  format; e.g., 5 not .05:";
cin >> rate;

system("pause");
return 0;
}``````

yeah i know its not much but i can sure use a hand. am i going to use "while" "do" "for" "count++" for this assignment?

You could probably use any flavor of loop you wish. Generally while loops are used if you aren't certain of the number of times you want to loop whereas for loops are used if you do know the number of times to loop. Do/while forces something to be done at least once.

alright so i been working on it and have been doing some good progress but Im not that great with getting calculations so im a bit stuck. I need to know how to get the total interest earned

Total interest earned: \$ 25.64

that way I can get the final balance.

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

int main()
{

int numMonths;
double numBalance;
float rate;
double totaldep = 0.0;
double totalwith = 0.0;

//starting balance
cout <<"Enter the initial balance:";
cin >> numBalance;
//Number of months
cout <<"Enter the number of months to cover:";
cin >> numMonths;

cout <<"Enter the annual interest rate (decimal  format; e.g., 5 not .05:";
cin >> rate;

for (int month = 1; month <= numMonths; month++)
{ double deposited, withdrawn;

cout <<"Enter the amount deposited for month" << month << ": ";
cin >> deposited;
cout <<"Enter the amount withdrawn for month" << month << ": ";
cin >> withdrawn;
totaldep += deposited;
totalwith += withdrawn;
}
cout << fixed << showpoint << setprecision(2);
cout <<"Starting balance:" << setw(26) << '\$' << numBalance << endl;
cout <<"Total amount deposited:"  << setw(20) << '\$' << totaldep << endl;
cout <<"Total amount withdrawn:"  << setw(20) << '\$' << totalwith << endl;

system("pause");
return 0;
}``````

First, you need to learn how to format your code. This will help with following the code -- for you and us. If we can't follow your code, we can't help much.

What is the calculation for calculating the interest for one month? How did you arrive at 25.64? If it was given to you by your instructor, how did he arrive at the value?

And while we're at it, check this out, too. Something you might want to ask your instructor about.

heres a sample run like i posted b4
Enter the initial balance ===> 1000

Enter the number of months to cover: ===> 3
Enter the annual interest rate (decimal format; e.g., 5 not .05) ===> 10
Enter the amount deposited for month 1 ===> 500
Enter the amount withdrawn for month 1 ===> 400
Enter the amount deposited for month 2 ===> 600
Enter the amount withdrawn for month 2 ===> 700
Enter the amount deposited for month 3 ===> 800
Enter the amount withdrawn for month 3 ===> 900

Starting balance: \$ 1000.00
Total amount deposited: \$ 1900.00
Total amount withdrawn: \$ 2000.00
Total interest earned: \$ 25.64
Final balance: \$ 925.64

Im guessing I have to do some math operationt to calculate the interest rate. but idk what. like rate(interest rate) = something something

i dont even know if rate(interest rate) should be a float.

hopefully you guys get what im saying

Suppose the annual interest rate is 10%. It means you'll get 10% of whatever amount is stored on an annual basis.
Be it the case you have 100\$ deposited for a whole year at 10% interest rate.

``````int deposit;
float interestRate, interest;
cin >> deposit; //In this case 100
cin >> interestRate; //In this case 10
interestRate /= 100.; //Use 100. not 100, so it would be regarded as a float type
interest = interestRate * depost; //Calculate the interest
deposit += interest; //Add the interest to the total deposit
cout << "Your total interest is " << interest << "." << endl;
cout << "Now the total deposit is " << deposit << "." << endl;``````

So the calculation you're looking for is just interest rate(as a float value) multiplied by the total deposited amount.

If the amount of deposited money changes every month, you would have to calculate them individually and finally add it up for each month.
Unless ofcourse you only want to give interest on the deposited money at exactly 1 year.
As an example, suppose there's been 1000\$ deposited for 11 months, during the 12th month everything is withdrawn, does the person still get interest for having his/her money there for 11 months, or does he/she get nothing?

im trying but still dont know how he got 25.64 for interest rate

my updated code

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

int main()
{

int numMonths;
double numBalance;
float interest, interestRate = 100.;
double totaldep = 0.0;
double totalwith = 0.0;

//starting balance
cout <<"Enter the initial balance:";
cin >> numBalance;
//Number of months
cout <<"Enter the number of months to cover:";
cin >> numMonths;

cout <<"Enter the annual interest rate (decimal  format; e.g., 5 not .05):";
cin >> interest;

for (int month = 1; month <= numMonths; month++)
{	int deposited, withdrawn;

cout <<"Enter the amount deposited for month" << month << ": ";
cin >> deposited;
cout <<"Enter the amount withdrawn for month" << month << ": ";
cin >> withdrawn;
totaldep += deposited;
totalwith += withdrawn;
interest = interestRate * deposited;
deposited += interest;
}

cout << fixed << showpoint << setprecision(2);
cout <<"Starting balance:" << setw(26) << '\$' << numBalance << endl;
cout <<"Total amount deposited:"  << setw(20) << '\$' << totaldep << endl;
cout <<"Total amount withdrawn:"  << setw(20) << '\$' << totalwith << endl;
cout <<"Total interest earned: " << setw(20) << '\$' << interest << endl;

system("pause");
return 0;
}``````
``````cin >> interest;
totaldep += deposited;
totalwith += withdrawn;
interest = interestRate * deposited;
deposited += interest;``````

You're asking the user to input a variable named interest(shouldn't it be interestRate anyway?), but where are you using it?
Using the same values you did, it would be something more like this:

``````cin >> interest;
totaldep += deposited;
interest /= 100.; //Go from percent value to float
interest *= deposited; //Calculate the actual interest
//interest /= 12; //Supposing the interest is annual, as said before, you would only want to give interest for one month, not an entire year.
deposited += interest;``````

Ofcourse, if you were to make a loop out of it, you'd have to have seperate variables for interest and interestRate. That is, if you don't want to request the user to input the interest rate every time.

till this day i still dont know how to do the calculation for interest to get 25.64

my code

``````#include <cmath>
#include <iomanip>
using namespace std;

int main()
{

int numMonths;
double numBalance;
float interest;
double totaldep = 0.0;
double totalwith = 0.0;

//starting balance
cout <<"Enter the initial balance:";
cin >> numBalance;
//Number of months
cout <<"Enter the number of months to cover:";
cin >> numMonths;

cout <<"Enter the annual interest rate (decimal  format; e.g., 5 not .05):";
cin >> interest;

for (int month = 1; month <= numMonths; month++)
{	float deposited, withdrawn;

cout <<"Enter the amount deposited for month" << month << ": ";
cin >> deposited;
cout <<"Enter the amount withdrawn for month" << month << ": ";
cin >> withdrawn;
totaldep += deposited;
totalwith += withdrawn;
interest /= 100.; //Go from percent value to float
interest *= deposited;
interest /= 12;
deposited += interest;
}

cout <<"Starting balance:" << fixed << showpoint << setprecision(2)<< setw(26) << '\$' << numBalance << endl;
cout <<"Total amount deposited:" << fixed << showpoint << setprecision(2) << setw(20) << '\$' << totaldep << endl;
cout <<"Total amount withdrawn:" << fixed << showpoint << setprecision(2) << setw(20) << '\$' << totalwith << endl;
cout <<"Total interest earned: " << setw(20) << '\$' << interest << endl;

system("pause");
return 0;
}``````

heres how it should run

Sample Run #1:

Enter the initial balance ===> 1000

Enter the number of months to cover: ===> 3
Enter the annual interest rate (decimal format; e.g., 5 not .05) ===> 10
Enter the amount deposited for month 1 ===> 500
Enter the amount withdrawn for month 1 ===> 400
Enter the amount deposited for month 2 ===> 600
Enter the amount withdrawn for month 2 ===> 700
Enter the amount deposited for month 3 ===> 800
Enter the amount withdrawn for month 3 ===> 900

Starting balance: \$ 1000.00
Total amount deposited: \$ 1900.00
Total amount withdrawn: \$ 2000.00
Total interest earned: \$ 25.64
Final balance: \$ 925.64

i need help there please!!!! i wan to get that part done so I can almsot be done.

monthlyInterestRate = (interestInput/100)/12;
totaldep += deposited;
totalwith += withdrawn;
balance = balance + deposited - withdrawn;
monthlyInterest = balance * monthlyInterestRate;
totalInterest += monthlyInterest;
balance += monthlyInterest;

that helped a lot but when i run it i still dont get it exactly like the sample running.

my update code

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

int main()
{

int numMonths;
double startingBalance;
double numBalance;
float interest;
double totaldep = 0.0;
double totalwith = 0.0;
double monthlyInterestRate = 0.0;
double totalInterest = 0.0;

//starting balance
cout <<"Enter the initial balance:";
cin >> startingBalance;
//Number of months
cout <<"Enter the number of months to cover:";
cin >> numMonths;

cout <<"Enter the annual interest rate (decimal  format; e.g., 5 not .05):";
cin >> interest;

for (int month = 1; month <= numMonths; month++)
{	int deposited, withdrawn;

cout <<"Enter the amount deposited for month" << month << ": ";
cin >> deposited;
cout <<"Enter the amount withdrawn for month" << month << ": ";
cin >> withdrawn;
monthlyInterestRate = (interest/100)/12;
totaldep += deposited;
totalwith += withdrawn;
numBalance = startingBalance + deposited - withdrawn;
monthlyInterestRate = numBalance * monthlyInterestRate;
totalInterest += monthlyInterestRate;
numBalance += monthlyInterestRate;
}

cout <<"Starting balance:" << fixed << showpoint << setprecision(2)<< setw(26) << '\$' << startingBalance << endl;
cout <<"Total amount deposited:" << fixed << showpoint << setprecision(2) << setw(20) << '\$' << totaldep << endl;
cout <<"Total amount withdrawn:" << fixed << showpoint << setprecision(2) << setw(20) << '\$' << totalwith << endl;
cout <<"Total interest earned: " << setw(20) << '\$' << totalInterest << endl;
cout <<"Final Balance:" << fixed << showpoint << setprecision(2) << setw(29) << '\$' << numBalance << endl;

system("pause");
return 0;
}``````

still cant get the exact or close total interest and the final balance is off too.

hmmm

Before I posted my recent post I had typed up something like this.

Simple interest takes a set amount of balance for a set amount of time. For example \$1000 at 10% per year for 1 year is 100 dollars interest. If you don't hold for 1 year you might not get any interest or it might be prorated. If it is prorated evenly distributed throughout the year, month by month, and you had balance of \$1000 for 3 months you would get \$25 dollars interest, etc. If you had \$1000 for 1 month you would get \$8.333333. If you had \$1100for one month you would get \$9.16666. If you had \$900 for 1 month you would get \$7.499999. If you add all the interest you get \$24.999996, or something close. To get more than \$25 in interest on an average balance of \$1000 dollars over 3 months you need to use compound interest, that is you need to earn interest in month 2 on the interest you earned in month 1 and in month 3 you need to earn interest on the interest you earned in months 1 and 2, etc. The problem becomes when you put money in and take money out each month what is the average monthly balance? In addition when do you do the calculations----on the balance at the end of the month, on the average daily balance, on the highest balance of the month, on the lowest balance of the month, etc. When I did the calculations by hand using end of month balance I got interest earned of \$25.22. You can do the calcluations on the other versions if you wish. It's not immediately obvious how the example came up with the value it did.