-5

I'm trying to create a structure that contains fields for account numbers, balances, and interest rates and I am supposed to use an array to do so.

I need the output to display like this:

Account number X has a balance of X and an interest rate of X.

The end user is supposed to be able to enter their account number (and if it's already in the system an error message should occur) their balance and their interest rate.

I'm stuck! I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know).

____UPDATE___

First of all- I'm 4 weeks into my first programming class ever- The text asks me to complete the tasks I will share below. We have not learned about std:... & vectors yet. This chapter covered parallel arrays and structure objects. But the only thing I've learned about structure objects is this: struct Part { int partNum; double partPrice; };

The rest of the above code just shows me how to enter in info as a programmer and not how to allow the user to enter in code.

You are developing a BankAccount structure for Parkville Bank. The structure contains fields for the account number, the account balance, and the annual interest rate earned on the account. Write a main()function in which you create an array of five BankAccount objects. Prompt the user for values for all the fields in the five BankAccounts. Do not allow two or more accounts to have the same account number. After all the objects have been entered: » Display all the data for all five accounts. » Display the total balance in all five accounts and the average balance. » After displaying the statistics, prompt the user for an account number and display the data for the requested account, or display an appropriate message if no such account number exists. Continue to prompt the user for account numbers until an appropriate sentinel value is entered.

none
  • 9
  • 1
  • 5

1 Answers1

2

Based on this: "I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know)" it seems like you are completely confused about how this kind of data can be grouped. One of the many possible ways is:

struct Account {
    std::string number;
    double balance;
    double interestRate;
};

representing a single element that can be used in some container holding accounts, e.g. :

std::vector<Account> accounts;

but since you mentioned the constraint: "I am supposed to use an array to do so", then unfortunately you'll have to use a C-style array:

Account accounts[N];

or in case you have no VLA support:

Account* accounts = new Account[N];
...
delete[] accounts;

Now get some good book and spend some time reading it before you continue writing codes.

Community
  • 1
  • 1
LihO
  • 41,190
  • 11
  • 99
  • 167