-
May 19th, 2009, 03:47 PM
#1
Function returs 0s as the values of structural member
Hi !
Here is a problem, ProcessCheck function returns temp2.debits = 0
I don't understand why ?
Code:
struct Record
{
int code;
double amount;
};
struct Totals
{
double debits;
double credits;
double service_fee;
};
int main()
{
int counter = 0;
double balance;
Record account;
Totals account_totals = {0,0,0};
ifstream inFile;
inFile.open("c:\\checkin.dat");
//Variable Declarations
DisplayTitle();
inFile >> balance;
DisplayBal(balance);
while(!inFile.eof())
{
account = GetData(inFile);
switch(account.code)
{
case 1: balance = ProcessCheck(balance, account, account_totals);
counter++; break;
case 2: balance = ProcessDeposit(balance,account, account_totals);
counter++; break;
case 3: balance = ProcessATM(balance, account, account_totals);
counter++; break;
}
DisplayBal(balance);
}
double ProcessCheck(double bal, Record temp1, Totals temp2)
{
cout << "\n Check = " << setw(10) << temp1.amount;
temp2.debits = temp1.amount + temp2.debits;
return (bal - temp1.amount);
}
Last edited by alexibm; May 19th, 2009 at 03:58 PM.
-
May 19th, 2009, 03:57 PM
#2
Re: Function returs 0s as the values of structural member
You don't appear to be attempting to return anything related to temp2.
Did you mean to pass temp2 by reference rather than by value?
-
May 19th, 2009, 04:05 PM
#3
Re: Function returs 0s as the values of structural member
ok ! In this case, is it possible to pass temp2 by reference rather than by value?
I am not sure it is possible for structures ?
-
May 19th, 2009, 04:52 PM
#4
Re: Function returs 0s as the values of structural member
Of course it's possible for structures. Why wouldn't it be?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|