You have a comma after your variable declaration:
double amount, // ^
Change that to a semicolon ;
.
Question
I received the following error in my compiler:
AccountDB.cpp: In member function ‘void AccountDB::processTransactions(const char*)’: AccountDB.cpp:89:9: error: expected initializer before ‘.’ token inFile2.open(transactFile); ^ (the carrot is over the period)
This is the relevant function. From similar errors on here, I suspect it has something to do with a namespace, but I'm not sure which. The function is supposed to read the date, account number and amount of a transaction and then process it using other nested functions.
void AccountDB::processTransactions(const char* transactFile)
{
//set up the input stream from the text file
ifstream inFile2;
//set up the variables to be read from text file
char date[6];
char type;
char accountnumber[20];
double amount,
//open the file
inFile2.open(transactFile);
//standard check for file and exit if it doesn't exist
if(!inFile2)
{
cout << "Error, input file could not be opened.\n";
exit(1);
}
//Creates a header for listing transactions
cout << setw(5) << "Date"
<< setw(25) << "Account Number"
<< setw(5) << "Type"
<< setw(8) << "Amount"
<< setw(30) << "New Balance"
<< endl;
inFile2 >> date;
while (inFile2)
{
inFile2 >> accountnumber >> type >> amount;
cout << setw(5) << date
<< setw(25) << accountnumber[20]
<< setw(5) << type
<< setw(8) << amount;
int relevantAccount = searchForAccount(accountnumber);
if (relevantAccount != -1)
{
if (type == 'P')
{
credArray[relevantAccount].processPayment(amount);
cout << setw(30) << credArray[relevantAccount].getBalance() << endl;
}
else
{
bool chargestatus = credArray[relevantAccount].processCharge(amount);
if (chargestatus = 1)
cout << setw(30) << credArray[relevantAccount].getBalance() << endl;
else
cout << "Credit limit exceeded" << endl;
}
}
else
cout << "Invalid account number" << endl;
inFile2 >> date;
}
cout << "End of transaction list." << endl;
}
Solution
You have a comma after your variable declaration:
double amount, // ^
Change that to a semicolon ;
.