Help with variable declaration please!

This is a discussion on Help with variable declaration please! within the C++ Programming forums, part of the General Programming Boards category; I am currently working on a RPG for the win32 console. I am using a structure to hold information on ...

  1. #1
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38

    Question Help with variable declaration please!

    I am currently working on a RPG for the win32 console. I am using a structure to hold information on a player. I was wondering if I could define a structure and declare that structure type right below it in the global declaration area (the area above main()) so that any function I use can modify the struct variable? In my RPG I want to have functions for shops and upgrading, and whenever they upgrade or buy/equip and item I want those functions to be able to modify the struct variable. I was thinking something like this:

    Code:
    #include <iostream> /* included to show that this is above main()*/
    #include <string> /* included to show that this is above main() */
    struct stats
    {
         char name[50];
         int health;
         int mana;
         char weapon[50];
         char armor[50];
         etc...
    }
    stats player;
    int newgame();
    int main()
    {
         char menu_choice;
         cout<<"Choose an option:"<<endl;
         cout<<"(N)ew Game"<<endl;
         cout<<"(L)oad Game"<<end;
         cout<<"(E)xit"<<endl;
         cin>>menu_choice;
         switch(strlwr(menu_choice))
         {
              case "n": newgame()
                   break;
              etc...
         }
         return 0;
    }
    int newgame()
    {
         cout<<"Please enter your character's name:"
         cin>>player.name
         etc...
    }
    I think if that would work it would be the most efficient, and more cipherable, if debuging, method. If anyone knows if this would work, or if you have a suggestion for a better way to store player stats please share!

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you could, but I would advise against it... you could just pass the structure by reference to the functions using it...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    god i'm an idiot.................
    but i just started like 3 days ago, and i come from a vb world (thank god i was converted).. so stfu to anyone who agrees to the previous line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  2. Error in global variable declaration
    By JFonseka in forum C Programming
    Replies: 4
    Last Post: 04-11-2008, 11:50 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. variable declaration in H file
    By aleccher in forum C Programming
    Replies: 5
    Last Post: 04-02-2003, 06:18 PM
  5. variable declaration style
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 05-20-2002, 02:32 PM

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