Getting wrong output from a class
Hi, I'm getting confused with this classes. Im able to pass values to the class, but I'm not getting the right output after I call it.
if the object is "noticed" (seen = 1) and the player doesn't have the object, then the program should display "you have picked up the.." when i call object::get but it keeps showing me "there's does not to be a ...anywhere.
here's the code:
Code:
#include <iostream>
#include <string>
using namespace std;
class object
{
private:
string name;
int where; // Where object is, -1 if carried
int seen; // If you have seen it
int have; // If you have it
public:
void setup(string n, int w, int s, int h);
int get(int room, int s, int h);
int noticed(int room, int s);
};
void object::setup(string n, int w, int s, int h)
{
name.assign(n);
where = w;
seen = s;
have = h;
}
int object::get(int room, int s, int h)
{
if (((room == where) || (where == -1)) && (s == 1) && (h == 0))
{
cout<< "You have picked up the "<< name <<"."<<endl;
have = 1;
return have;
}
else if (s != 1)
{
cout << "There does not seem to be a " << name << " anywhere." <<endl;
return 0;
}
else if (h == 1)
{
cout<< "You already have the "<< name <<"."<<endl;
return 1;
}
else
{
cout<<"You cannot get the "<< name <<"."<<endl;
return 0;
}
}
int object::noticed(int room, int s)
{
if(s == 0)
{
cout<<"You notice a "<<name<<"."<<endl;
seen = 1;
return seen;
}
else
{
cout<<"You don't see anything"<<endl;
return s;
}
}
int main()
{
object something;
int s = 0;
int h = 0;
something.setup("can", 1, 0, 0);
something.get(1, s, h);
something.noticed(1, s);
return 0;
}