Please Help

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

int main()
{
double balance;
double deposit;
double withdrawl;
double interest;
double gainedInt;
double monthlyInt;
int num = 1;
double intBalance;

cout << "Please enter the initial balace: ";
cin >> balance;

intBalance = balance;

cout << "Please enter the annual interest rate: ";
cin >> interest;

monthlyInt = interest / 12;


while (num < 4)
{
cout << " Month " << num << endl;
cout << " Total Balance: " << balance << endl;
cout << " Enter the total deposited: " << endl;
cin >> deposit;
balance = balance + deposit;
cout << " Enter the total withdrawn: " << endl;
cin >> withdrawl;
balance = balance - withdrawl;
gainedInt = balance*monthlyInt;
balance = balance + gainedInt;
num = num + 1;
}


cout << " Starting Balance: " << intBalance << endl;
cout << " Annual interest rate (%): " << interest << endl;
cout << "Month 1 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;
cout << "Month 2 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;
cout << "Month 3 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;

return 0;
}

this is my code so far, I need help getting the deposit values from the loop, and into the last part of my code, I know that I am using the same int for the last part, I just don't know how to individually change it.
Read this entire chapter and all the sub-chapters it contains:
http://www.programming4beginners.com/tutorial/chapter10/arrays

And use the code tag next time.
Please use code tags! It helps us read your code more clearly and allows for more accurate error finding.
http://www.cplusplus.com/articles/jEywvCM9/
Thanks for the replies and sorry for the code tag error, this is my first post, I read the article and I'm still not sure how to use the array in my code, further assistance would help a lot if possible, thanks for your time so far @Kevin C
#include<vector>

...

int main()
{
double balance;
vector<double> deposit(4);

...

cin >> deposit[num];
balance = balance + deposit[num];
...

cout << "Month 1 Deposit " << deposit[1] << ...
Last edited on
kevin, you made an error on line 8 of your example. you put parentheses around 4 instead of brackets. Also, here is the code in a code tag.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double balance;
double deposit;
double withdrawl;
double interest;
double gainedInt;
double monthlyInt;
int num = 1;
double intBalance;

cout << "Please enter the initial balace: ";
cin >> balance;

intBalance = balance;

cout << "Please enter the annual interest rate: ";
cin >> interest;

monthlyInt = interest / 12;


while (num < 4)
{
cout << " Month " << num << endl;
cout << " Total Balance: " << balance << endl;
cout << " Enter the total deposited: " << endl;
cin >> deposit;
balance = balance + deposit;
cout << " Enter the total withdrawn: " << endl;
cin >> withdrawl;
balance = balance - withdrawl;
gainedInt = balance*monthlyInt;
balance = balance + gainedInt;
num = num + 1;
}


cout << " Starting Balance: " << intBalance << endl;
cout << " Annual interest rate (%): " << interest << endl;
cout << "Month 1 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;
cout << "Month 2 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;
cout << "Month 3 Deposit " << deposit << " , Withdrawal " << withdrawl << endl;

return 0;
}
Topic archived. No new replies allowed.