Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4026170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:56:13+00:00 2026-05-20T10:56:13+00:00

/*I got stumped within my code. I think classes will be simpler than structures,

  • 0

/*I got stumped within my code. I think classes will be simpler than structures, but the chapter within my book makes me do structures. : / I am currently getting an error message that my function was not matched up for an overloaded function. The book does talk about them, but the examples of overloading functions in the book aren’t helping me out. Also the book wants me to enter account numbers and fill in the objects and when they are asked for an account number they should have the opportunity to “QUIT” entering numbers and proceed onto the next part of the program; that whole way of thinking has my brain a bit fried and I was hoping I could get some help. I apologize if the formatting of my code is messy, I tried to reformat it within here so it would all go into the code brackets.

The Error happens at line… 161 at the displayAccounts function. Parameters were different within the top and bottom of the two functions I changed it and it works. I am going to go over different parts and if its correct post the correct code.*/

I figured out exactly the question that I need. I need the “QUIT” loop to be allowed to be followed up within the account numbers. This would allow the user to enter in a 0 at any time when asked to enter an account number and this was what was confusing me the most.

#include <iostream>
#include <iomanip>

using namespace std;

struct BankAccount
{
    void enterAccountsData(BankAccount *accounts);
    void computeInterest(BankAccount *accounts);
    void displayAccounts(BankAccount *accounts, const int QUIT);

    int accountNum; // holds the account number.
    double accountBal; // holds the account balance.
    double annualInterest; // holds the interest rate.
    int term; // holds the term for the accounts.
};

int main()
{
    const int MAX_ACCOUNTS = 100; // The maximum number of bank accounts.
    const int QUIT = 0; // sentinal value.
    int input;
    int num = 0;
    BankAccount data[MAX_ACCOUNTS];
    BankAccount display;

    cout << "Enter " << QUIT << " to stop, otherwise enter 1 and procreed.";
    cin >> input;

    while(true)
    {
        if(input != QUIT)
        {
            data[MAX_ACCOUNTS].enterAccountsData(data);
            data[MAX_ACCOUNTS].computeInterest(data);
        }
        else
        {
            break;
        }
    }

    display.displayAccounts(data, QUIT);
    //system("pause");
    return 0;
}

void BankAccount::enterAccountsData(BankAccount *accounts)
{
    cout << setprecision(2) << fixed;

    const int NUM_OF_ACCOUNTS = 100; // the number of bank accounts. (change the number for more bank accounts)
    int found;
    int quit = 0;

    /* First for loop which asks and holds the account information
    entered in by the user. */
    for(int num = 0; num < NUM_OF_ACCOUNTS; num++)
    {
        do
        {
            found = 0;
            cout << "Enter in account # " << (num + 1) << endl;
            cin >> accounts[num].accountNum; // holds the value of the account number

            // Checks if the account number is valid.
            while(accounts[num].accountNum < 999 || accounts[num].accountNum > 10000)
            {
                cout << "Account number must be four didgets:" << endl;
                cin >> accounts[num].accountNum;
            }
            // Checks if the account numbers are the same.
            for(int check = 0; check < num; check++)
            {
                while(accounts[num].accountNum == accounts[check].accountNum)
                {
                    cout << endl << "Account Numbers cannot be the same, enter in a new account number." << endl;
                    found = 1;
                    break;
                }
            }
        } while(found); // end of do while.

        // Holds the values for the account balances.
        cout << "Enter the accounts balance."  << endl;
        cin >> accounts[num].accountBal;

        // Makes sure that the account balance is not negative.
        while(accounts[num].accountBal < 0)
        {
            cout << "Account cannot have a negitive balance." << endl;
            cin >> accounts[num].accountBal;
        }
        // Holds the interest rate.
        cout << endl << "Enter the interest rate for account # " << (num + 1) << endl;
        cin >> accounts[num].annualInterest;

        // Makes sure the interest rate is valid
        while(accounts[num].annualInterest > 0 && accounts[num].annualInterest > 0.15)
        {
            cout << endl << "Annual interest must be from 0 to 0.15." << endl;
            cin >> accounts[num].annualInterest;
        }
        // Makes sure the interest rate is not negetive
        while(accounts[num].annualInterest < 0)
        {
            cout << endl << "Interest rate cannot be negetive" << endl;
            cin >> accounts[num].annualInterest;
        }
        // Holds the value for the length of the interest.
        cout << endl << "How many years will this interest rate be held for? " << endl;
        cin >> accounts[num].term;

        //Checks for valid length of time for the term held
        while(accounts[num].term < 0 || accounts[num].term > 11)
        {
            cout << "The Term must be greater than 1 and should not exceed 10" << endl;
            cin >> accounts[num].term;
        }
    }
    cout << "If you wish to stop enter 0 otherwise type 1 to proceed" << endl;
    cin >> quit;
    if(quit = 0)
    {
        return;
    }
}

void BankAccount :: computeInterest(BankAccount *accounts)
{
    const int NUM_OF_ACCOUNTS = 100; // the number of bank accounts.
    const int MONTHS_IN_YEAR = 12;
    double total = 0;
    double average = 0;

    for(int num = 0; num < NUM_OF_ACCOUNTS; num++)
    {
        /*Goes through the term year and calculates the total
        of each account balance. Then calculates the average. */

        for(int year = 0; year < accounts[num].term; year++)
        {
            for(int month = 0; month < MONTHS_IN_YEAR; month++)
            {
                accounts[num].accountBal = (accounts[num].accountBal * accounts[num].annualInterest) + accounts[num].accountBal;
            }
            int month = 1;
            cout << endl << "Total amount for account # " << (num + 1) << " is: " << accounts[num].accountBal << endl ;
            total += accounts[num].accountBal;
            cout << endl << "The total amount of all accounts is: " << total << endl;
        }
    }
    average = total / NUM_OF_ACCOUNTS;
    cout << "Average of all the bank accounts is: " << average << endl;
}

void BankAccount :: displayAccounts(BankAccount *accounts)
{
    int input = 0;
    int found;
    const int MAX_ACCOUNTS = 100;
    int quit = 0;

    cout << endl << "Which account do you want to access?" << endl <<
    "To stop or look at none of the account numbers type: " << quit << endl;
    cin >> input;

    for(int num = 0; num < MAX_ACCOUNTS; num++)
    {
        while(num < MAX_ACCOUNTS && input != accounts[num].accountNum)
        {
            num++;
        }
        if(input == accounts[num].accountNum) // This if sees if an account matches what the user entered.
        {
            cout << "Account: " << accounts[num].accountNum << endl << "Balance is: " <<
            accounts[num].accountBal << endl << "Interest rate is: " << accounts[num].annualInterest;
            cout << endl << "Enter another account number or type 0 to quit." << endl;
            found = 1;
            cout << endl;
            cin >> input;
        }
        if(found == 0)
        {
            cout << "Sorry that account doesn't exist. Enter another account number." << endl;
            cin >> input;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:56:13+00:00Added an answer on May 20, 2026 at 10:56 am

    In C++, classes and structs are exactly the same constructs. They are, in fact, one thing — a User-Defined Type.

    There is a different that is invoked depending on whether you used the keyword struct or class to define your UDT, and that is that class-key defaults to private member access and private inheritance, whereas struct-key defaults to both being public.

    Other than this syntax difference, you can use either without worrying about one being “simpler” than the other.

    Anyway, your compiler error (please provide it next time) is probably due to a declaration/definition mismatch.

    Your declaration:

    void displayAccounts(BankAccount *accounts, const int QUIT);
    

    Start of your definition:

    void BankAccount :: displayAccounts(BankAccount *accounts) {
    

    The start of the definition should be

    void BankAccount::displayAccounts(BankAccount* accounts, const int QUIT) {
    

    to match. I’ve also fixed your spacing to be nicer. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now
got a new blog at wordpress few days ago ( http://ghads.wordpress.com ) and I
Got a class that serializes into xml with XMLEncoder nicely with all the variables
Got myself in a bit of a pickle here ... working on a CMS
Got a problem with ADOMD.NET 8.0, SQL2008 and our app. It isn't giving us
Got a bit of a mind freeze at the moment. I have the following
I got into a mini-argument with my boss recently regarding project failure. After three
I got a webserver with a running application. There's a webpage with a form:
I got this error today when trying to open a Visual Studio 2008 project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.