| | |
your help is needed (loops)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 61
Reputation:
Solved Threads: 0
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
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?
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
C++ Syntax (Toggle Plain Text)
#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?
•
•
Join Date: Mar 2008
Posts: 61
Reputation:
Solved Threads: 0
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.
Total interest earned: $ 25.64
that way I can get the final balance.
C++ Syntax (Toggle Plain Text)
#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.
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.
Last edited by WaltP; Nov 23rd, 2008 at 1:41 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Mar 2008
Posts: 61
Reputation:
Solved Threads: 0
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
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
Last edited by anbuninja; Nov 23rd, 2008 at 1:51 am.
•
•
Join Date: Sep 2008
Posts: 55
Reputation:
Solved Threads: 9
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.
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?
Be it the case you have 100$ deposited for a whole year at 10% interest rate.
C++ Syntax (Toggle Plain Text)
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;
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?
Last edited by BeyondTheEye; Nov 23rd, 2008 at 8:53 am.
•
•
Join Date: Mar 2008
Posts: 61
Reputation:
Solved Threads: 0
im trying but still dont know how he got 25.64 for interest rate
my updated code
my updated code
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Sep 2008
Posts: 55
Reputation:
Solved Threads: 9
C++ Syntax (Toggle Plain Text)
cin >> interest; totaldep += deposited; totalwith += withdrawn; interest = interestRate * deposited; deposited += interest;
Using the same values you did, it would be something more like this:
C++ Syntax (Toggle Plain Text)
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.
Last edited by BeyondTheEye; Nov 23rd, 2008 at 6:30 pm.
•
•
Join Date: Mar 2008
Posts: 61
Reputation:
Solved Threads: 0
till this day i still dont know how to do the calculation for interest to get 25.64
my code
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.
my code
C++ Syntax (Toggle Plain Text)
#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.
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 263
monthlyInterestRate = (interestInput/100)/12;
totaldep += deposited;
totalwith += withdrawn;
balance = balance + deposited - withdrawn;
monthlyInterest = balance * monthlyInterestRate;
totalInterest += monthlyInterest;
balance += monthlyInterest;
totaldep += deposited;
totalwith += withdrawn;
balance = balance + deposited - withdrawn;
monthlyInterest = balance * monthlyInterestRate;
totalInterest += monthlyInterest;
balance += monthlyInterest;
Last edited by Lerner; Dec 4th, 2008 at 7:15 pm.
Klatu Barada Nikto
![]() |
Similar Threads
- A bit of help needed with loops (C)
- help with parrallel arrays (C++)
- Some assistance needed (Pascal and Delphi)
- asp code generated as text, needed to be seen as asp code again. databses backup (ASP)
- just a little help needed (C++)
- Urgent help needed (Pascal and Delphi)
- Fork and exec to run external needed app (C++)
- Help with while, do while, and for loops (C++)
- needed recursion help (C)
Other Threads in the C++ Forum
- Previous Thread: Using Bubble sort to sort Arrays please help
- Next Thread: C++ graphics
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






