Reputation: 13
Been stuck on this for a very long time and cant work out a solution, keep getting error message array type 'int [8]' is not assignable. Also it is tellig me that the array entries 'expresssion must be a modifiable lvalue' I've tried to look up multiple times and just can't seem to think of anything, any help is useful thanks :) using namespace std;
const int MAXACCOUNTS = 8;
int main()
{
cout << "Welcome" << endl;
int counter = 0;
int counter1 = 0;
int interest_counter = 0;
struct Account
{
int AccountNumber[MAXACCOUNTS] ;
double Balance[MAXACCOUNTS];
int DaySinceDebited[MAXACCOUNTS];
};
Account entries[MAXACCOUNTS];
while (counter1 != MAXACCOUNTS)
{
if (counter1 = 0)
{
entries[counter1].AccountNumber = 1001;
entries[counter1].Balance = 4254.40;
entries[counter1].DaySinceDebited = 20;
counter += 1;
}
else if (counter1 = 1)
{
entries[counter1].AccountNumber = 7940;
entries[counter1].Balance = 27006.25;
entries[counter1].DaySinceDebited = 35;
counter += 1;
}
else if (counter1 = 2)
{
entries[counter1].AccountNumber = 4382;
entries[counter1].Balance = 123.50;
entries[counter1].DaySinceDebited = 2;
counter += 1;
}
else if (counter1 = 3)
{
entries[counter1].AccountNumber = 2651;
entries[counter1].Balance = 85326.92;
entries[counter1].DaySinceDebited = 14;
counter += 1;
}
else if (counter1 = 4)
{
entries[counter1].AccountNumber = 3020;
entries[counter1].Balance = 657.00;
entries[counter1].DaySinceDebited = 5;
counter += 1;
}
else if (counter1 = 5)
{
entries[counter1].AccountNumber = 7168;
entries[counter1].Balance = 7423.34;
entries[counter1].DaySinceDebited = 360;
counter += 1;
}
else if (counter1 = 6)
{
entries[counter1].AccountNumber = 6245;
entries[counter1].Balance = 4.99;
entries[counter1].DaySinceDebited = 1;
counter += 1;
}
else if (counter1 = 7)
{
entries[counter1].AccountNumber = 9342;
entries[counter1].Balance = 107864.44;
entries[counter1].DaySinceDebited = 45;
counter += 1;
}
}
cout << "Acct No Balance Interest Paid" << endl;
while (counter != MAXACCOUNTS)
{
cout << entries[counter].AccountNumber << " " << entries[counter].Balance << " " << entries[counter].DaySinceDebited << endl;
counter += 1;
}
return 0;
}
Upvotes: 0
Views: 1254
Reputation: 15446
You've declared AccountNumber
, Balance
and DaySinceDebited
as arrays, but you try to assign them individual values. You're treating them as if they're not arrays because logically it doesn't make sense for them to be arrays. Remember, you have multiple accounts (an array of accounts), but each account only has a single AccountNumber, Balance, etc... Don't make them arrays. Instead declare them as:
int AccountNumber;
double Balance;
int DaySinceDebited;
Also, in each of your if
's, you need to use ==
for comparison. As of now, your statements look like:
else if (counter1 = 1) {
^^^
This will assign the value of 1
to counter1
and then check if it evaluates to true. Since all integers (except 0) evaluate to true in C++, this will always be run. Change these to be:
else if (counter == 1) {
Upvotes: 2