portaccount.txt file wont edit, i cant find where i am going wrong.

In this program when I withdraw money I want the PortAccount.txt to change to the new value of when money has been withdrawn, however it changes in the program but the .txt file value isn't changing whatsoever, I think its a problem with the loop but I cant seem to do it, the code that needs repairing is below.

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  #include <fstream>
#include <cstring>
#include <string>
#include <iostream>
#include <ctime>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {

	const string user= "dan123";
	const string pass = "password";
	const string accnum = "2364288";
	string entnum;
	string entpass;
	int newb;
	int inputted;
	int portbalance;
	string translist;
	int attempts = 0;
	int attempt = 0;
	int subtramount;
	time_t now = time(0);
	char* dt = ctime(&now);


	fstream bank;
	fstream transactions;

	bank.open("PortAccount.txt");
	transactions.open("TransList.txt", ios::app);


	cout << "Welcome to Port Wage Manager v1.2" << endl;
	cout << "Please enter your account number : " << endl;
	cin >> entnum;

	while (entnum !=accnum && attempt < 3)
	{
		cout << "Account number incorrect try again: " << endl;
		cin >> entnum;
		attempt++;
	}

	if (attempt < 3)
	{
		cout << "User Identified, Welcome " << user << endl;
	}
	else
	{
		cout << "All attempts failed, system will now close" << endl;

		system("Pause");

		return 0;
	}

	cout << "Please enter password " << user << endl;
	cout << "Enter here" << endl;
	cin >> entpass;

	while (entpass !=pass && attempts < 3)
	{
		cout << "Access Failed try again: " << endl;
		cin >> entpass;
		attempts++;
	}

	if (attempts < 3)
	{
		cout << "Access Granted ";
	}
	else
	{
		cout << "Three attempts failed, system will now shut down" << endl;

		system("Pause");

		return 0;
	}

	do
	{


		bank >> portbalance;

		cout << "Account Balance is = " << portbalance << endl << endl;

		cout << "Enter 1 for Bank Transfer" << endl;
		cout << "Enter 2 to display last 5 transactions" << endl;
		cout << "Enter 3 to display account details" << endl;
		cout << "Enter 4 to exit program" << endl;

		cin >> inputted;

		switch (inputted)	
		{
		case 1:
			cout << "How much do you want to withdraw? : " <<  endl;
			cin >> subtramount;

			transactions << " -" << subtramount << setw(5) << " User: " << user << setw(5) << dt;

			cout << "Transaction successful, you withdrew " << subtramount << " GBP at " << dt << endl;

			portbalance = portbalance - subtramount;

			if (portbalance <= 0)
			{
				cout << "Error, withdrawal cancelled, you have insufficient funds" << endl;

				transactions << "Withdrawal attempt cancelled for " << setw(3) << subtramount << "at " << dt; 

				break;
			}

			cout << "Your balance is " << portbalance << endl;

			bank << portbalance;

			break;
Have you stepped through it with a debugger? That will help you see if and when it's actually executing line 121.
it all runs smoothly but the txt file wont change its value, theres a way in which you need to get the program to create a file with the same name as the one you read in but still new to C++
Topic archived. No new replies allowed.