Judas 0 Newbie Poster

Hello
Im hoping someone could help me with this code, i have used comment notations to show problem areas.
If anyone has suggestions on how to improve this code or see's something i have used that may be wrong(mixing the wrong class or code) please reply.

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

using namespace std;

int displayroom(int roomnum)
{
      char filename [ FILENAME_MAX ];
      sprintf(filename, "%d.txt", roomnum);
      char ch2;
      ifstream fin(filename );               // i want to use ios class's and ios::noreplace but i get error ?
      if (fin.bad()) cout<<"An Error has happend on opening the file";
      while (fin.get(ch2))
      cout<<ch2;
      cout<<"\n";
      fin.close();
}


int roomsave(string roomname,string roomdisc,int roomnum)
{
      char filename [ FILENAME_MAX ];
      sprintf(filename, "%d.txt", roomnum);
      
      ofstream fout(filename);
      if (fout.bad()) cout<<"An Error has happend saving the file";
      fout<<endl<<roomname<<endl<<endl;
      fout<<roomdisc;
      fout.close();
} 


int roomedit(int roomnum)
{
    string roomname, roomdisc;

    cout<<"Room Name: ";             // how do i use getline on these two cin lines 
    cin>>roomname;                   // when i have used them the program shows both cout on same line and only takes one entry
    cout<<"Room Discription: ";      // also i would like to know how i save these to a specific a line in file
    cin>>roomdisc;                   
    
    roomsave(roomname, roomdisc, roomnum);
}


int movement(string ch, int roomnum)
{
    
    displayroom(roomnum);
}

int main()
{
    string ch;
    int ct = 0;
    
    int roomnum;
    if (ct== 0) roomnum = 100;
        ct++;
        
    displayroom(roomnum);
do{
        cin>>ch;
    // is there a simpler way to write these if statements?
    if (ch=="n" || ch=="north" || ch=="e" || ch=="east" || ch=="s" || ch=="south" 
        || ch=="w" || ch=="west" || ch=="ne" || ch=="northeast" || ch=="nw" 
        || ch=="northwest" || ch=="se" || ch=="southeast" || ch=="sw" || ch=="southwest" 
        || ch=="u" || ch=="up" || ch=="d" || ch=="down")
        {
        roomnum++;
        movement(ch, roomnum);
        }
    if (ch=="edit")
        {
        roomedit(roomnum);
        }  
    if (ch=="l" || ch=="look")
        {
        displayroom(roomnum);      
        }
    if (ch=="back" || ch=="b")
        {
        roomnum--;
        displayroom(roomnum);
        }
        
  }
while (ch!="q" && ch!="quit");
    
    
    //system("PAUSE");
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.