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.tx t");
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_descriptio n);
cout << Sounds[n].Sound_number <<endl;
cout << Sounds[n].Sound_descriptio n <<endl;
}
}
}
void ReadItemsFile(structItem Items[])
{
ifstream inFileItems;
inFileItems.open("items.tx t");
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);
}
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.tx
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
{
ifstream inFileSounds;
inFileSounds.open("sounds.
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_descriptio
cout << Sounds[n].Sound_number <<endl;
cout << Sounds[n].Sound_descriptio
}
}
}
void ReadItemsFile(structItem Items[])
{
ifstream inFileItems;
inFileItems.open("items.tx
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);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dang JKr, I need you on speed dial
those changes worked perfectly.
now I can move on to the next step.. oh bother
:-)
those changes worked perfectly.
now I can move on to the next step.. oh bother
:-)
ASKER
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp
c:\adventure\adventrue.cpp