Arrays, loops, I need help

Write your question here.

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

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

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

intBalance = balance;

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

monthlyInt = interest / 12;


for (num = 0; num < 3;num+1)
{
cout << " Enter the total deposited: " << endl;
cin >> deposit;
cout << " Enter the total withdrawn: " << endl;
cin >> withdrawl;
if (deposit > 0 && withdrawl < balance + deposit) {
balance = balance + deposit;
balance = balance - withdrawl;
gainedInt = balance*monthlyInt;
balance = balance + gainedInt;
num = num + 1;
}
else {
cout << " You have entered an invalid number" << endl;
return 0;
}
}


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, I need to get all of the deposits and withdrawals to get different outputs, please bare with my messy post, I really need help
first mistake
wrong way of increment in
for (num = 0; num < 3;num+1)

use this
for (num = 0; num < SIZE; num++)

second mistake is
use array for these two
1
2
int deposit;
int withdrawl;

as you want to stroe all the previous values too.

Here is my code
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
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <iomanip>
using namespace std;

#define SIZE 3

int main()
{
	double balance;
	int deposit[SIZE];
	int withdrawl[SIZE];
	double interest;
	double gainedInt;
	double monthlyInt;
	int num = 0;
	double intBalance;

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

	intBalance = balance;

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

	monthlyInt = interest / 12;


	for (num = 0; num < SIZE; num++)
	{
		cout << " Enter the total deposited: " << endl;
		cin >> deposit[num];
		cout << " Enter the total withdrawn: " << endl;
		cin >> withdrawl[num];
		if (deposit[num] > 0 && withdrawl[num] < balance + deposit[num])
		{
			balance = balance + deposit[num];
			balance = balance - withdrawl[num];
			gainedInt = balance*monthlyInt;
			balance = balance + gainedInt;
		}
		else
		{
			cout << " You have entered an invalid number" << endl;
			return 0;
		}
	}


	cout << " Starting Balance: " << intBalance << endl;
	cout << " Current Balance: " << balance << endl;
	cout << " Annual interest rate (%): " << interest << endl;
	for (num = 0; num < SIZE; num++)
	{
		cout << "Month " << num+1 << " Deposit:" << deposit[num] << " , Withdrawal " << withdrawl[num] << endl;
	}

	return 0;
}


Here is output
Please enter the initial balace: 12000
Please enter the annual interest rate: 12
 Enter the total deposited: 
1000
 Enter the total withdrawn: 
1000
 Enter the total deposited: 
1000
 Enter the total withdrawn: 
1000
 Enter the total deposited: 
2000
 Enter the total withdrawn: 
1000
 Starting Balance: 12000
 Current Balance: 98000
 Annual interest rate (%): 12
Month 1 Deposit:1000 , Withdrawal 1000
Month 2 Deposit:1000 , Withdrawal 1000
Month 3 Deposit:2000 , Withdrawal 1000

Topic archived. No new replies allowed.