Thread: Homework Help

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    8

    Homework Help

    Hey there everyone!

    So I'm coming to this forum at the last minute but I know I won't be able to fix it and get a submission in time but that's my own fault. Had my code working before I closed it one night, displaying everything I needed it to, and when I went to work on it next time the function I was editing wasn't working. I am working on an advanced bank project and I wanted to add a restriction that displayed for the user the list of customer accounts that had more than a particular amount in all their collective accounts. Here's my code to display it all.

    Code:
    string Bank::listCustomersWithHoldingsAbove(int ammount)
    {
        string result;
        result += "\n";
            for (int i = 0; i < vAccount.size(); i++)
            {
                if (ammount < vAccount[i].balance)
                {
                    result += padRight("", '_', 9) + " ";
                    result += padRight("", '_', 12) + " ";
                    result += padRight("", '_', 12) + " ";
                    result += padRight("", '_', 12) + "\n";
                    
                    result += padRight("Customer#", '.', 9) + " ";
                    result += padRight("Name", '.', 12) + " ";
                    result += padRight("DOB", '.', 12) + " ";
                    result += padRight("SSN", '.', 12) + "\n";
                    result += padRight("Account#", '.', 9) + " ";
                    result += padRight("Account Type", '.', 12) + " ";
                    result += padRight("Balance", '.', 12) + "\n";
                
                    result += padRight(intToString(vCustomer[i].customerNumber), ' ', 9) + " " +
                        padRight(vCustomer[i].name, ' ', 12) + " " +
                        padRight(vCustomer[i].birthdate, ' ', 12) + " " +
                        padRight(vCustomer[i].SSnumber, ' ', 12) + "\n";
                    result += padRight(intToString(vAccount[i].accountNumber), ' ', 9) + " " +
                        padRight(vAccount[i].accountType, ' ', 12) + " " +
                        padRight(intToDollarString(vAccount[i].balance), ' ', 12) + "\n";
                    
                    result += padRight("", '_', 9) + " ";
                    result += padRight("", '_', 12) + " ";
                    result += padRight("", '_', 12) + " ";
                    result += padRight("", '_', 12) + "\n";
                    return "These customers have their account balance higher than: " + intToDollarString(ammount) + "\n" + result;
                }
                else
                {
                    return "Sorry, you don't have any customers with more than " + intToDollarString(ammount) + " in your bank. \nCongratulations. You're poor.";
                }
            }
    }
    For some reason, it stops at the very first account that it sees meet the restriction in this case. When the program opens I have 5 accounts, each with a little more than 10 and one account with over 400 in it. It doesn't run through all of them NOR does it link up with any of the random accounts I add into the program via a separate AddAccounts function.

    Is there anything I can do to make it so it runs through everything I need it to in the program? Perhaps a *this pointer?

    Thanks in advance everyone!

    intro_to_see

  2. #2
    Guest
    Guest
    On lines 34 and 38, your function returns. The loop will not keep executing after that. Also, your program should draw its conclusions after having checked every customer, not while doing so. You need to rethink that logic.

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    8
    Adrian,
    Thanks! I got half of the problem fixed. I moved the return statement and eliminated the else statement to prevent it from stopping after the first one. Still need to fix the loop though.

    Regards,
    intro_to_see

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help...
    By pSyXaS in forum C Programming
    Replies: 2
    Last Post: 05-08-2011, 02:21 AM
  2. Need help on my homework
    By mejv3 in forum C++ Programming
    Replies: 15
    Last Post: 10-11-2005, 03:43 PM
  3. Homework Help
    By shadowctr in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2005, 07:29 PM
  4. Homework Help Please
    By mars4bb in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2005, 05:16 PM
  5. ok, yes, I need help with my homework!
    By melee in forum C Programming
    Replies: 5
    Last Post: 09-22-2004, 07:42 AM