Credit card payment remembering overpayments

Hi!
I'm new to this site so I am sorry if I put my code in the wrong format. Anyway....
I have a program that reads credit card accounts, payments and charges from a file. The problem I am having is making a payment to an account that goes over the balance of the account. So if the balance on the account is $50 and I pay $100 my program shows a -$50. I want to show this +$50 or something that shows that there is extra money but I need to remember that the next time the card gets charged then I have to subtract the extra amount from the charged amount.
For example:
Balance: $50 Payment to account 1: $101
Balance: +$51 Charge to account 1: $51
Balance: $0

Also how do I check for end of file? The file.eof() is not working for this
Last edited on
bruh...
you don't have a main function.
and you're defining functions in their prototype heading
AND since you don't have a main function; you're not making any calls to those functions...
Here's the code with everything implemented properly;
you still have to make the function calls and make sure everything is working properly.
But it compiles at it is now, although it does nothing.
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
124
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;
const int MAX = 100;

struct ACCOUNT
{
int accNum;
string name;
double balance;
double acclimit;
};
                 // make functions prototypes
void sort(ACCOUNT , int );
int toSearch(ACCOUNT, int , int );
ACCOUNT Accounts(istream& , ACCOUNT& );
void PrintSingle(ostream& , int , double , double , ACCOUNT);
void Payment(istream& , ostream& , ACCOUNT, int );

int main()
{
    // make calls here
    
    return 0;
}

void sort(ACCOUNT cust[], int size)
{
ACCOUNT t;
for (int i = 0; i < size; i++)
{
for(int j = i + 1; j < size; j++)
{
if(cust[i].accNum > cust[j].accNum)
{
t.accNum = cust[i].accNum;
cust[i].accNum = cust[j].accNum;
cust[j].accNum = t.accNum;
t.name = cust[i].name;
t.balance = cust[i].balance;
t.acclimit = cust[i].acclimit;
cust[i].name = cust[j].name;
cust[i].balance = cust[j].balance;
cust[i].acclimit = cust[j].acclimit;
cust[j].name = t.name;
cust[j].balance = t.balance;
cust[j].acclimit = t.acclimit;
}
}
}
}

int toSearch(ACCOUNT cust[], int size, int target)
{
int beg = 0, end = size-1;
int mid = (beg + end) / 2;

if (target == cust[end].accNum)
{
return end;
}
if (target == cust[beg].accNum)
{
return beg;
}

while(beg < end)
{
if(target == cust[mid].accNum)
{
return mid;
}
else if(cust[mid].accNum > target)
{
end = mid;
}
else
{
beg = mid + 1;
}
mid = (beg + end)/2;
}
return -1;
}

ACCOUNT Accounts(istream& in, ACCOUNT& customers)
{
in >> customers.accNum;
in >> customers.name;
in >> customers.balance;
in >> customers.acclimit;
return customers;
}

void PrintSingle(ostream& out, int loc, double oldBal, double amount, ACCOUNT customers[])
{
out << left<< setw(10) << "Account"<< "|\t"<< setw(10)<< "Old Balance"<<"|\t"<< setw(10)<< "New Balance"<<"|\t"<< setw(10)<<"Credit Limit\n";
out <<"-------------------------------------------------------------\n";
out << setw(10)<< customers[loc].accNum <<"|\t"<< setw(10)<< oldBal<<" |\t"<< setw(10)<< customers[loc].balance<<" |\t";
out << setw(10)<< customers[loc].acclimit << endl;
}

void Payment(istream& in, ostream& out, ACCOUNT customers[], int count)
{
double amount, oldBal;
int target, loc;

in >> target >> amount;
loc = toSearch(customers, count, target);

if(loc == -1)
{
out << "Account " << target << " not found." << endl;
return;
}
oldBal = customers[loc].balance;
customers[loc].balance -= amount;
out << "\n\n*Paying $" << amount << " to Account " << target << endl;
PrintSingle(out, loc, oldBal, amount, customers);

}
Topic archived. No new replies allowed.