Array in struct question

I have a struct in the header with a char customer[50] and double cardBalance[10] and it accepts data just fine.
My questions is, when I am trying to print out the data, the name prints out just fine while the balance prints the first balance correctly followed by all zeros.

Here is the section of my code.
I am wondering what I did wrong...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// File.h
enum AcctType { Visa, AmEx, Discover, MasterCard };
struct Accounts
{
	char customer[50];
	int acctId;
	double balance;
	AcctType cardType;
	double cardBalance[20];
};

//---------------

// File.cpp
Accounts acct1 = { "John Doe", 101, 1424.32, Visa, 593.32 };
Accounts acct2 = { "Jane Doe", 102, 3235.75, AmEx, 5646.24 };

Accounts bankAccounts[3];
bankAccounts[0] = acct1;
bankAccounts[1] = acct2;


printf ( "%s \t%d \t$%.2f \t%d \t$%.2f\n", bankAccounts[0].customer, bankAccounts[0].acctId, bankAccounts[0].balance, bankAccounts[0].cardType, bankAccounts[0].cardBalance[0] );
printf ( "%s \t%d \t$%.2f \t%d \t$%.2f\n", bankAccounts[1].customer, bankAccounts[1].acctId, bankAccounts[1].balance, bankAccounts[1].cardType, bankAccounts[1].cardBalance[0] );


John Doe        101     $1254.35        0       $593.32
Janet Doe       102     $3235.75        1       $5646.24


Why is it that I can increment the customer name's array but not the card balance?

Thank you.
what zeros are you talking about?... it looks like it did print out correctly...

John Doe        101     $1254.35        0       $593.32
Janet Doe       102     $3235.75        1       $5646.24
Why is cardBalance an array of 20? You are only entering 1 value when you construct the objects. Can 1 card of 20 values for balance? I don't really understand your question but what I do know is that there are 19 values in the cardBalance array that you never assigned a value to.
Topic archived. No new replies allowed.