Your syntax is off; I would suggest checking over it again. Assuming you are using C, you also need to prefix the type names with the word struct unless you use a typedef.
I posted here before and my post totally didn't answer your question at all XD Sorry about that. For some reason I thought you were asking a completely different quesiton.
ANYWAY:
price apple = 6;
This does not work. The reason for this is because 6 is type 'int' and not type 'price', and the compiler has no idea what you're trying to do by assigning that.
Disch that's OK and I just wanna know if we could add value to the object of the structure but pether has eliminated my doubt. Because the book always use sort of like the array stuff for the structure, that really pigues me to ask such a question.
But how come pether's code work? because of the member of apple which has been defined as type int?
1 2 3 4 5 6 7 8 9 10
struct price{
int apple;
int pineapple;
int pear;
int orange;
} price, amountofmoneyneededtobuy;
price.apple = 5;
price.pear = 9;
amountofmoneyneededtobuy.orange = 8;
The question is whether it is ok just to initialize
struct_type_name name_of_variable = constant
If you provide a constructor which takes one integer as argument to the struct, you can:
1 2 3 4 5 6 7
struct price
{
int x;
int y;
price ( int value ) : x ( value ), y ( value ) {} // assign both x and y to 'value'
};
price apple = 6; // apple.x and apple.y are set to 6