Structured arrays

I working on an assignment that processes an array of structs. In the main function I am attempting to declare an array of Author structures with 3 elements. It is supposed to be initialized to set all of the string fields (the names and book titles) to "NONE", and the double fields (the prices) to zero. This is supposed to be done in one statement, not using loops. Here is what I have.



1
2
3
4
5
 struct BookInfo      struct Author
       {                    {
	 string title;        string authorName;
	 double price;        BookInfo books[SIZE] //SIZE = 3
       };                   };                                   


1
2
3
4
5
6
7
8
9
10
11
12
//prototype for function to print the content of array on screen
      void showInfo(Author a[], int size);	
      //prototype for function to allow user to enter values into array
      void getInfo(Author a[], int size);

     const int SIZE = 3;

int main()
{                   //authorName//title,price
	Author a[] = { {"NONE", {{"NONE",0}, {"NONE",0}, {"NONE",0}}, 
				{{"NONE",0}, {"NONE",0}, {"NONE",0}},
				{{"NONE",0}, {"NONE",0}, {"NONE",0}},	} } ;


I was under the impression that an array can only hold the values of one data type. So doubles and strings in the same array doesn't make sense to me. However, that's the example my teacher drew up. The error keeps telling me that there are too many initializer values. How do I fix this? Any help would be greatly appreciated!
I was under the impression that an array can only hold the values of one data type
I't can only hold one data type. The data type of your array is the struct which happens to hold a couple of data types
How then would I display an array of Author structures with 3 elements?
closed account (3UMLy60M)
1
2
3
4
5
Author a[SIZE] = {
		{"NONE", { {"NONE", 0}, {"NONE", 0}, {"NONE", 0} } },
		{"NONE", { {"NONE", 0}, {"NONE", 0}, {"NONE", 0} } },
		{"NONE", { {"NONE", 0}, {"NONE", 0}, {"NONE", 0} } }
	};

Try this and let me know how it goes.
That works perfect. Thanks
Topic archived. No new replies allowed.