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 3981800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:27:14+00:00 2026-05-20T05:27:14+00:00

I am having trouble with my code. I cannot seem to understand how to

  • 0

I am having trouble with my code. I cannot seem to understand how to implement my balances into the arrays while using structures. Is there anyone that could help me?

#include <iostream>
#include <iomanip>

using namespace std;    

struct BankAccount
{
    int accountNum;
    double accountBal;
    double annualIntrest;
    int term;
};
int main()
{
    const int BANKACC = 5;
    const int QUIT = 1;
    const int MONTHS_IN_YEAR = 12;
    int x,found,input,month;
    double total = 0;
    double average = 0;
    BankAccount accounts[BANKACC];

    for(x = 0; x < BANKACC; x++)
    {
        do
        {
            found = 0;
            cout << "Enter in account # " << (x + 1) << endl;
            cin >> accounts[x].accountNum;
            while(accounts[x].accountNum < 1000 || accounts[x].accountNum > 9999)
            {
                cout << "Account number must be four didgets:" << endl;
                cin >> accounts[x].accountNum;
            }
            for(int check = 0; check < x; check++)
            {
                while(accounts[x].accountNum == accounts[check].accountNum)
                {
                    cout << endl << "Account Numbers cannot be the same, enter in a new account number." << endl;
                    found = 1;
                    break;
                }
            }
        } while(found); 

        cout << "Enter the accounts balance."  << endl;
        cin >> accounts[x].accountBal;
        while(accounts[x].accountBal < 0)
        {
            cout << "Account cannot have a negitive balance." << endl;
            cin >> accounts[x].accountBal;
        }
        cout << "Enter the interest rate." << endl;
        cin >> accounts[x].annualIntrest;
        while(accounts[x].annualIntrest > 0 && accounts[x].annualIntrest > 0.15)
        {
            cout << "Annual interest must be from 0 to 0.15." << endl;
            cin >> accounts[x].annualIntrest;
        }
        cout << "How many years will the term be held for? " << endl;
        cin >> accounts[x].term;

            while(accounts[x].term < 1 || accounts[x].term > 10)
            {
                cout << "The Term must be greater than 1 and should not exceed 10" << endl;
                cin >> accounts[x].term;
            }
    }
    for(int year = 1; year < accounts[x].term; year++)
    {
        for( month = 1; month < MONTHS_IN_YEAR; month++)
        { 
            accounts[x].accountBal = accounts[x].accountBal * accounts[x].annualIntrest + accounts[x].accountBal;
            total += accounts[x].accountBal;
            x++;

        }
        month = 1;
        average = total  / BANKACC;
    }
    for(x = 0; x < BANKACC; x++)
    {
        cout << "Account # " << (x + 1) << "'s number is: " << accounts[x].accountNum;
        cout << " The accounts balance is: " << accounts[x].accountBal;
        cout << " The interest on the account is: " << accounts[x].annualIntrest << endl;
    }

    cout << "Average of all the bank accounts is: " << average << endl;

    cout << "Which account do you want to access?" << endl <<
        " To stop or look at none of the account numbers type " << QUIT << endl;    
        for(x = 0; x < BANKACC; x++)
        {
            cout << accounts[x].accountNum << "    ";
        }
        cin >> input;

        while(input != QUIT)
        {
            found = 0;
            x = 0;
            while(x < BANKACC && input != accounts[x].accountNum)
            {
                x++;            
            }
                if(input == accounts[x].accountNum)
                {
                    cout << "Account:" << accounts[x].accountNum << " balance is: " <<
                    accounts[x].accountBal << " Interest rate is: " << accounts[x].annualIntrest;
                    cout << endl << "Enter the another account number or type 1 to quit.";
                    found = 1;
                    cin >> input;
                }
            if(found == 0)
            {
            cout << "Sorry that account doesn't exist. Enter another account number.";
            cin >> input;
            }
        }
    system("pause");
    return 0;
}
  • 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-20T05:27:14+00:00Added an answer on May 20, 2026 at 5:27 am

    Some problems I noticed :

    1. What if in accounts[x].term is also 1 ? Ans: You would never get in to that loop.
    2. Are you actually computing the average of all bank accounts? Ans: No
    3. You said account must be of 4 digits. So, 1000 & 9999 are valid account numbers. So, your condition should have been – while( accounts[x].accountNum < 999 || accounts[x].accountNum > 10000) ) { /.... }

    Assuming that, user will always enter intergers only between 1 to 10 for term, try this –

    for( int x=0; x < BANKACC; ++x )
    {
        for(int year = 1; (year < accounts[x].term) || (year==accounts[x].term); ++year)
        {
            for( month = 0; month < MONTHS_IN_YEAR; ++month)
            { 
                accounts[x].accountBal += accounts[x].accountBal * accounts[x].annualIntrest;
                total += accounts[x].accountBal;
            }
        }
    }
    average =(double) (total  / BANKACC);
    

    Also, if had set the warnings on while compilation, you should have got useful messages regarding array out of bounds.

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

Sidebar

Related Questions

Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
I'm having trouble with this code: NSRect itemFrame; id item; // code to assign
As the title suggests, I am having trouble maintaining my code on postback. I
I am having some trouble with this code . The problem is when i
I'm writing some code in python and I'm having trouble when trying to retrieve
Im having trouble using a .NET COM in vb6, It compiles ok and I
I having trouble in dividing the HTML frames. I have been using the following
I've been having trouble getting my ASP.NET application to automatically log users into the
I'm having trouble within a block of code that I believe is related to
When we remote a method (that is using generics) the remoting sink cannot seem

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.