My main code variable declaration (just declaration no login statement)

struct AXEMAN{
       int lvl;
       int att;
       int hp;};
struct DEFENDER{
       int lvl;
       int att;
       int hp;};
struct ARCHER{
       int lvl;
       int att;
       int hp;};
struct SPEARMAN{
       int lvl;
       int att;
       int hp;};
struct ROUGE{
       int lvl;
       int att;
       int hp;};

#include "header.h"                         / have to under struct... so that the struct has been declared

int main(int argc, char *argv[])
{
      struct AXEMAN axeman;
      struct DEFENDER defender;
      struct ARCHER archer;
      struct ROUGE  rouge;
      struct SPEARMAN spearman;
                   
      string input;
      int sel_MainMenu=99,sel_GameMenu=99,sel_SubGameMenu=99,sel_Motion=99;
      int sel_Movement_num=99;
      char sel_Movement;
      int sel_char_num=99,sel_enermy_num=99;
      char sel_char,sel_enermy;
      int comp_dmg,player_dmg,comp_hp,player_hp;
      int quit=0;
      int error=0;
      char matrix[70][50];               //x=70 , y=50
      int x,y;
      bool detected_comp=0,detected_player=0,skip=0;

==================================================
This code will be called under "header.h" (my subfunction in another .c file)

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
{
     axeman. lvl=1;
     axeman. att=40;
     axeman. hp=450;
     defender. lvl=1;
     defender. att=30;
     defender. hp=500;
     archer. lvl=1;
     archer. att=50;
     archer. hp=300;
     spearman. lvl=1;
     spearman. att=45;
     spearman. hp=400;
     rouge. lvl=1;
     rouge. att=35;
     rouge. hp=350;
}

PROBLEM:
`ARCHER' was not declared in this scope
`archer' was not declared in this scope

SO:
what is the way i have to declare variable...
or my header file calling method has problem?

thx for help

struct AXEMAN axeman;
struct DEFENDER defender;
struct ARCHER archer;
struct ROUGE  rouge;
struct SPEARMAN spearman;

In C++ you don't have to supply the 'struct' word each time before you declare a struct-variable, though it's still allowed to do so, you can save some typing :) ...

Edit:: I don't get what you mean, do you have compiler errors ? (please post them if so)

subfunction.cpp:16: error: variable or field `initialize_status_player' declared void
subfunction.cpp:16: error: `AXEMAN' was not declared in this scope
subfunction.cpp:16: error: `axeman' was not declared in this scope
subfunction.cpp:16: error: `DEFENDER' was not declared in this scope
subfunction.cpp:16: error: `defender' was not declared in this scope
subfunction.cpp:16: error: `ARCHER' was not declared in this scope
subfunction.cpp:16: error: `archer' was not declared in this scope
subfunction.cpp:16: error: `SPEARMAN' was not declared in this scope
subfunction.cpp:16: error: `spearman' was not declared in this scope
subfunction.cpp:16: error: `ROUGE' was not declared in this scope
subfunction.cpp:16: error: `rouge' was not declared in this scope
subfunction.cpp:17: error: initializer expression list treated as compound expression
subfunction.cpp:17: error: expected `,' or `;' before '{' token
subfunction.cpp:35: error: variable or field `initialize_status_comp' declared void
subfunction.cpp:35: error: `AXEMAN' was not declared in this scope
subfunction.cpp:35: error: `axeman' was not declared in this scope
subfunction.cpp:35: error: `DEFENDER' was not declared in this scope

subfunction.cpp:35: error: `defender' was not declared in this scope
subfunction.cpp:35: error: `ARCHER' was not declared in this scope
subfunction.cpp:35: error: `archer' was not declared in this scope
subfunction.cpp:35: error: `SPEARMAN' was not declared in this scope
subfunction.cpp:35: error: `spearman' was not declared in this scope
subfunction.cpp:35: error: `ROUGE' was not declared in this scope
subfunction.cpp:35: error: `rouge' was not declared in this scope

subfunction.cpp:36: error: initializer expression list treated as compound expression
subfunction.cpp:36: error: expected `,' or `;' before '{' token
subfunction.cpp: In function `void initialize_weapon(char (*)[50])':
subfunction.cpp:61: error: `random_weapon' undeclared (first use this function)
subfunction.cpp:61: error: (Each undeclared identifier is reported only once for each function it appears in.)

these are part of the error only..

struct AXEMAN{
       int lvl;
       int att;
       int hp;};
struct DEFENDER{
       int lvl;
       int att;
       int hp;};
struct ARCHER{
       int lvl;
       int att;
       int hp;};
struct SPEARMAN{
       int lvl;
       int att;
       int hp;};
struct ROUGE{
       int lvl;
       int att;
       int hp;};

#include "header.h"                         / have to under struct... so that the struct has been declared

int main(int argc, char *argv[])
{
      struct AXEMAN axeman;
      struct DEFENDER defender;
      struct ARCHER archer;
      struct ROUGE  rouge;
      struct SPEARMAN spearman;
                   
      string input;
      int sel_MainMenu=99,sel_GameMenu=99,sel_SubGameMenu=99,sel_Motion=99;
      int sel_Movement_num=99;
      char sel_Movement;
      int sel_char_num=99,sel_enermy_num=99;
      char sel_char,sel_enermy;
      int comp_dmg,player_dmg,comp_hp,player_hp;
      int quit=0;
      int error=0;
      char matrix[70][50];               //x=70 , y=50
      int x,y;
      bool detected_comp=0,detected_player=0,skip=0;
      
      initialize_board(matrix);                       //Get Random comp hero
      initialize_status_player(axeman, defender, archer, spearman, rouge);     //initialize hero's status      
      introduce();
      MainMenu();                       //Get the selection of Main Menu      
      while (sel_MainMenu==99)
      {
          input=Input();
          sel_MainMenu=errorCheck_num (input);
          show_error (sel_MainMenu);
      }
      
      if(sel_MainMenu==1)                             //If MAIN MENU SELECTION == 1 (new game)
      {
          initialize_weapon(matrix);                      
          initialize_body (matrix);                    
      }
      else if (sel_MainMenu==2) 
           load (axeman, defender, archer, spearman, rouge);
      else 
      {
            cout<<"Bye bye...\n\n\n";
            quit=1;
      }
void initialize_board(char matrix[][50])
{
     for(int i=0;i<70;i++)
     for(int j=0;j<50;j++)
     {
     matrix[i][j]=' ';
     }
}

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
{
     axeman. lvl=1;
     axeman. att=40;
     axeman. hp=450;
     defender. lvl=1;
     defender. att=30;
     defender. hp=500;
     archer. lvl=1;
     archer. att=50;
     archer. hp=300;
     spearman. lvl=1;
     spearman. att=45;
     spearman. hp=400;
     rouge. lvl=1;
     rouge. att=35;
     rouge. hp=350;
}

void initialize_status_comp(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
{
     axeman. lvl=1;
     axeman. att=40;
     axeman. hp=450;
     defender. lvl=1;
     defender. att=30;
     defender. hp=500;
     archer. lvl=1;
     archer. att=50;
     archer. hp=300;
     spearman. lvl=1;
     spearman. att=45;
     spearman. hp=400;
     rouge. lvl=1;
     rouge. att=35;
     rouge. hp=350;
}

void initialize_weapon(char matrix[][50])
{
     matrix[4][17]=')';
     matrix[4][22]='p';
     matrix[4][27]='>';
     matrix[4][32]=']';
     matrix[4][37]='}';
     matrix[55][17]=random_weapon ();
     matrix[55][22]=random_weapon ();  
     matrix[55][27]=random_weapon ();
     matrix[55][32]=random_weapon ();
     matrix[55][37]=random_weapon ();
}
void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge);
void initialize_board(char matrix[][50]);
void initialize_weapon(char matrix[][50]);

1st code block is my main.c
2nd code block is my subfunction.c
3rd code block is my header.h

If this is C++ code you should rename your files to main.cpp, subfunction.cpp and header.h, this will reduce the errors you're having ...

Is this actually your whole code as I can't seem to find the following functions:

> introduce();
> MainMenu();
> Input();
> errorCheck_num (input);
> show_error (sel_MainMenu);
> initialize_body (matrix);
> load (axeman, defender, archer, spearman, rouge);

In the code you posted, the main-function is missing a '}' at the end ...

This article has been dead for over six months. Start a new discussion instead.