struct question

This is a discussion on struct question within the C++ Programming forums, part of the General Programming Boards category; One quick question... probably easy, I'm just a little confused. Code: struct sword_class { char name[15]; int damage; int price; ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    12

    struct question

    One quick question... probably easy, I'm just a little confused.

    Code:
    struct sword_class
    {
    	char name[15];
    	int damage;
    	int price;
    };
    
    sword_class swordz[3] = {
    {"Short Sword", 6, 50},
    {"Long Sword", 8, 100},
    {"Dagger", 3, 10}};
    If you can, how would you for example be able to print to the screen a part of this {"Short Sword", 6, 50}, would I be able to output the price separately from the others?

    Thanks in advance,
    -Psycho

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    Yes, with -

    cout << swordz[0].price;

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    12
    ohhhh

    thanks again
    -Psycho

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 03:14 AM
  2. Struct question... difference between passing to function...
    By Sparrowhawk in forum C++ Programming
    Replies: 6
    Last Post: 02-23-2009, 03:59 PM
  3. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-02-2007, 12:48 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 02:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21