I am having a problem assigning a value to a variable in a struct. I'm placing my whole code to see if anyone can spot a problem, but the area I am having trouble with is the function CHARGE_PAYMENTS, last function at the bottom of the page.
more detail:
in the last function CHARGE_PAYMENTS I am reading from file Month1 of customer charges and payments. what I am trying to do is match the customer account number with what is stored in one of the structs ( I have checked the struct SDbase Cstmr and all the customer data is saved (account#, name, address, balance). I figured that it would be easier to cycle through the customers to match the 1st account # entry on the file vs cycling the file entries against one customer at a time. The goal is to make a match between the saved record of a customer and an entry in Month1.txt in the 1st IF statement --> then in the second IF statement sends the value of "money" to either PAYMENT or CHARGE.
Each payment or charge variable can hold 10 and 15 entries respectively (a record)
If anyone can see what the problem is with my function at the bottom that would be very helpful. Also, how can I pass a STRUCT by reference when it has brackets? for some reason I get errors when placing & on it.
ex.
struct: Example myFile[x]
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//STRUCTS//
struct cInput
{
double payment[10];
double charge[15];
};
struct FNC
{
double Balance;
double tPayments; //total payments
double tCharges; //total cahrges
cInput Card;
};
struct SDbase
{
int memberNumb;
string name;
string address;
FNC account;
};
//PROTOTYPE//
int CNT_CUST();
void READ_DATA_FILE(SDbase Cstmr[], int size);
void CHARGE_PAYMENTS(SDbase Cstmr[], int size);
//---------------------------------------------------
ifstream CSTMR("Customer.txt");
ifstream MNT1("Month1.txt");
ifstream MNT2("Month2.txt");
int main()
{
int size;
size = CNT_CUST();
SDbase Cstmr[size];
FNC Records;
cInput cCard;
READ_DATA_FILE(Cstmr, size);
CHARGE_PAYMENTS(Cstmr, size);
CSTMR.close();
MNT1.close();
MNT2.close();
return 0;
}
//FUNCTION//
//Reads Customer file and counts the number of customers (lines)
int CNT_CUST()
{
string value = " "; int cnt = 0;
while(getline(CSTMR, value))
cnt++;
return cnt;
}
//Reads Customer information to Struct SDbase
void READ_DATA_FILE(SDbase Cstmr[], int size)
{
ifstream CSTMR("Customer.txt");
int acc;
char nm[16];
char adrs[20];
double bal;
for(int i = 0; i < size; i++)
{
CSTMR >> acc;
Cstmr[i].memberNumb = acc;
CSTMR.ignore(3);
CSTMR.get(nm, 16);
Cstmr[i].name = nm;
CSTMR.ignore(1);
CSTMR.get(adrs, 20);
Cstmr[i].address = adrs;
CSTMR.ignore(11);
CSTMR >> bal;
Cstmr[i].account.Balance = bal;
}
CSTMR.close();
}
//Submits Charges or Payments to Strut cInput using SDbase Cstmr
void CHARGE_PAYMENTS(SDbase Cstmr[], int size)
{
ifstream MNT1("Month1.txt");
int accNb = 0, x = 0;
double money = 0;
string tag;
while(MNT1 >> accNb)
{
MNT1 >> tag;
MNT1 >> money;
for(int i = 0; i < size; i++)
{
if(accNb == Cstmr[i].memberNumb)
{
if(tag == "PAYMENT")
{
Cstmr[i].account.Card.payment[x] = money;
x++;
}
else
{
Cstmr[i].account.Card.charge[x] = money;
x++;
}
}
}
}
MNT1.close();
}
|
This is what I need to do for this assignment.
there are 10 customers, each has a store account that either logs payments or charges to a personal store credit log. If the store owes the customer money, then the customer's account reflects it, and vice versa.