running totals... ledger need some help

I am trying to make a ledger of some sort. The ledger will prompt the user for a beginning balance and then three transactions following that using the letters "D" and "W" for deposit and withdraw respectively.

The input should look like:

Please enter your beginning balance: $200.00
Please enter the first transaction: D 1000.50
Please enter the second transaction: W 400.00
Please enter the third transaction: D 1505.50

Then I need to figure out how to calculate these running totals but that is where I am completely stumped. How do I go about do this? I also don't understand how I will make the program know that D will make an addition and W will subract. Here is my code so far:

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
#include <iostream>

using namespace std; 

int main() {
	
	double begin, first, second, third;
	
	cout << "Enter your beginning balance: " << endl;
	cin >> begin;
	
	cout << "Use the letter D for deposit or W for withdrawal" << endl;
	cout << "Enter your first transaction: " << endl;
	cin >> first;
	
	cout << "Enter your second transaction: " << endl;
	cin >> second;
	
	cout << "Enter your first transaction: " << endl;
	cin >> third;
	
	
	system("PAUSE");
	
	return 0;
}
I left some for you to do.

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
#include <iostream>

using namespace std; 
char TransType;
double NewBalance=0;

int main() {
	
	double begin, first, second, third;
	
	cout << "Enter your beginning balance: " << endl;
	cin >> begin;
	NewBalance=begin;

	cout << "Use the letter D for deposit or W for withdrawal" << endl;
	cout << "Enter your first transaction: " << endl;
	cin >> TransType >> first;

	if (TransType=='W')
		{NewBalance=NewBalance-first;}
	else if (TransType=='D')
		{NewBalance=NewBalance+first;}

	cout << "Starting Balance: \t" << begin << endl;
	cout << "Transaction Summary: \t" << NewBalance-begin << endl;
	cout << "Current Balance: \t" << NewBalance << endl;
	
	return 0;
}


Last edited on
Topic archived. No new replies allowed.