Link to home
Start Free TrialLog in
Avatar of chad
chad

asked on

text based game assistance (note:homework)

I am working on a school project that is a text based game.  I need to read in from three data files.
I think I am calling the other functions from main in correctly... I have no idea...


#include <iostream>
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;


void ReadRoomsFile(structRoom Rooms[])
  {
  ifstream inFileRooms;
  inFileRooms.open("rooms.txt");
  if (!inFileRooms)
        cout <<"Error... file not found";
  else
  {
        for (int n=0; n<5; n++)
        {
              string endlthing;
          inFileRooms>>                  Rooms[n].Room_number;
          inFileRooms>>                  Rooms[n].sound;
          getline (inFileRooms, endlthing);                  // this is required to grab the endl between int and getline
          getline (inFileRooms, Rooms[n].Room_desc_short);

          for (int i = 0; i<6; i++)
              inFileRooms >>Rooms[n].exit[i];
       
          string s ="";
          getline (inFileRooms, endlthing);                  // this is required to grab the endl between int and getline
          do
          {
                    getline (inFileRooms,s);
                    if (s!="")
                    {
                          Rooms[n].Room_desc_long = Rooms[n].Room_desc_long + s;
                  Rooms[n].Room_desc_long = Rooms[n].Room_desc_long + "\n";
                    }
              }
        
          while (s!="");

          cout << Rooms[n].Room_number            <<endl;
              cout << Rooms[n].sound                  <<endl;
          cout << Rooms[n].Room_desc_short      <<endl;

          for (int i = 0; i<6; i++)
              cout <<Rooms[n].exit[i]<<" ";
              cout <<endl;

          cout <<Rooms[n].Room_desc_long      <<n<<endl<<endl;
        }
  }
  }


void ReadSoundsFile(structSound Sounds[])
  {
        ifstream inFileSounds;
  inFileSounds.open("sounds.txt");
  if (!inFileSounds)
        cout <<"Error... Sound file not found";
  else
  {
        for (int n=0; n<2; n++)
        {
              cout<< "testing";
          inFileSounds>>                  Sounds[n].Sound_number;
          //getline (inFileRooms, endlthing);                  // this is required to grab the endl between int and getline
          getline (inFileSounds, Sounds[n].Sound_description);

         

          cout << Sounds[n].Sound_number                        <<endl;
              cout << Sounds[n].Sound_description                  <<endl;
         
        }
  }
  }

void ReadItemsFile(structItem Items[])
{
  ifstream inFileItems;
  inFileItems.open("items.txt");
  if (!inFileItems)
        cout <<"Error... Item file not found";
  else
  {
        for (int n=0; n<2; n++)
        {
      
          inFileItems>>                  Items[n].Item_number;
              inFileItems>>                  Items[n].Item_sound;
              inFileItems>>                  Items[n].Item_location;
          //getline (inFileRooms, endlthing);                  // this is required to grab the endl between int and getline
          getline (inFileItems, Items[n].Item_description);
   

          cout << Items[n].Item_number                        <<endl;
              cout << Items[n].Item_description                  <<endl;
         
        }
  }
}


int main ()
{
  struct structRoom
  {
        int            Room_number;
        int            sound;
        string      Room_desc_short;
        int            exit[6];
        string      Room_desc_long;
      
  };
  struct structSound
  {
        int            Sound_number;
        string      Sound_description;
  };
  struct structItem
  {
        int            Item_number;
        int            Item_sound;
        int            Item_location;
        string      Item_description;
  };
 
  structRoom      Rooms[30];
  structSound      Sounds[15];
  structItem      Items[25];

 ReadRoomsFile      (structRoom            Rooms[]);
 ReadSoundsFile      (structSound      Sounds[]);
 ReadItemsFile      (structItem            Items[]);
 
    int x;
    cin >> x;
    return (0);
}
 

Avatar of chad
chad

ASKER

He is a partial list of the errors I am getting.....

c:\adventure\adventrue.cpp(10): error C2065: 'structRoom' : undeclared identifier
c:\adventure\adventrue.cpp(10): error C2146: syntax error : missing ')' before identifier 'Rooms'
c:\adventure\adventrue.cpp(10): error C2182: 'ReadRoomsFile' : illegal use of type 'void'
c:\adventure\adventrue.cpp(10): error C2059: syntax error : ')'
c:\adventure\adventrue.cpp(11): error C2143: syntax error : missing ';' before '{'
c:\adventure\adventrue.cpp(11): error C2447: '{' : missing function header (old-style formal list?)
c:\adventure\adventrue.cpp(57): error C2065: 'structSound' : undeclared identifier
c:\adventure\adventrue.cpp(57): error C2146: syntax error : missing ')' before identifier 'Sounds'
c:\adventure\adventrue.cpp(57): error C2182: 'ReadSoundsFile' : illegal use of type 'void'
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chad

ASKER

Dang JKr, I need you on speed dial
those changes worked perfectly.
now I can move on to the next step.. oh bother
:-)