CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    35

    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.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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?

  3. #3
    Join Date
    Mar 2009
    Posts
    35

    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 ?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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
  •  





Click Here to Expand Forum to Full Width

Featured