fix errors #include <time.h> #include <iostream> #include <sstream> typedef unsi
ID: 3574486 • Letter: F
Question
fix errors
#include <time.h>
#include <iostream>
#include <sstream>
typedef unsigned char byte;
enum gResult { finish, p_New, p_Same };
enum object : byte { nothng, wump = 1, bat = 2, pit = 4, player = 8 };
connst unsigned S_player = 0, S_wump = 1, S_bat1 = 2, S_bat2 = 3, S_pit1 = 4, S_pit2 = 5,
max_Rooms = 20, saved = 6, max_Exits = 3, Path_Length = 5, maximum_Arrows = 5;
class InAndOut
{
public:
int GetLetterFromUser( std::string s, int a, int b )
{
int c;
do
{
message( s );
std::string r; std::cin >> r;
std::cin.Clear(); std::cin.ignore();
c = toupper( r[0] );
}
while( c != a && c != b );
return c;
}
int GetNumberFromUser( std::string s )
{
int n = 0; std::string c;
while( true )
{
message( s );
std::getline( std::cin, c );
std::stringstream strm( c );
if( strm >> n ) break;
}
return n;
}
void message( std::string s ) { std::cout << s; }
void message( int i ) { std::cout << i; }
void Wait() { std::cin.get(); }
};
class Rooms_available
{
public:
int getExit( int i ) { return exits[i]; }
byte conntains() { return obj; }
void Clear( object o ) { obj ^= o; }
void ClearRoom() { obj = nothng; }
void setExit( int i, int e ) { exits[i] = e; }
void Populate( object o ) { obj |= o; }
private:
int exits[max_Exits];
byte obj;
};
class Caves_available
{
public:
Caves_available()
{
int conn[] = { 1, 4, 7, 0, 2, 9, 1, 3, 11, 2, 4, 13, 0, 3, 5, 4, 6, 14, 5, 7, 16, 0, 6, 8, 7, 9, 17, 1, 8, 10, 9, 11, 18,
2, 10, 12, 11, 13, 19, 3, 12, 14, 5, 13, 15, 14, 16, 19, 6, 15, 17, 8, 16, 18, 10, 17, 19, 12, 15, 18 };
for( int x = 0, r = 0; x < max_Rooms; x++, r = x * max_Exits )
{
for( unsigned c = r, d = 0; c < r + max_Exits; c++, d++ )
Rooms_availables[x].setExit( d, conn[c] );
}
Clear();
}
void Clear()
{
for( int x = 0; x < max_Rooms; x++ )
Rooms_availables[x].ClearRoom();
}
Rooms_available* getRoom( int i ) { return &Rooms_availables[i]; }
private:
Rooms_available Rooms_availables[max_Rooms];
};
class Wumpus_in
{
private:
InAndOut InAndOut;
Caves_available theCave;
unsigned playerPos, Wumpus_inPos, pathLen, arrowsCnt, exits[max_Exits], arrowPath[Path_Length], saved[saved];
bool gameOver, playerWins;
void Look_out()
{
Rooms_available* r = theCave.getRoom( playerPos );
InAndOut.message( " ----------------------------------- " );
InAndOut.message( "You are in Rooms_available #" ); InAndOut.message( playerPos + 1 );
InAndOut.message( " Tunnels lead to Rooms_availables #: " );
for( int x = 0; x < max_Exits; x++ )
{
InAndOut.message( ( 1 + r->getExit( x ) ) );
InAndOut.message( " " );
}
Look_outAround( r );
}
void Shoot_around()
{
Rooms_available* r = theCave.getRoom( playerPos );
unsigned e;
for( unsigned x = 0; x < pathLen; x++ )
{
for( e = 0; e < max_Exits; e++ )
if( r->getExit( e ) == arrowPath[x] ) break;
if( e < max_Exits ) r = theCave.getRoom( arrowPath[x] );
else r = theCave.getRoom( r->getExit( rand() % max_Exits ) );
byte o = r->conntains();
if( wump & o ) { gameOver = playerWins = true; return; }
if( player & o )
{
gameOver = true; playerWins = false;
InAndOut.message( " OUCH! Arrow got you! " ); return;
}
}
InAndOut.message( " Missed! " );
if( --arrowsCnt == 0 )
{
InAndOut.message( " You run out of arrows... " );
gameOver = true; playerWins = false;
return;
}
Wumpus_inMove( playerPos );
}
gResult showResult( bool pw )
{
if( pw ) InAndOut.message( " AHA! You got the Wumpus! HEE HEE HEE - The Wumpus'll getcha next time!! " );
else InAndOut.message( " HA HA HA - You lose! " );
if( InAndOut.GetLetterFromUser( "Play again (Y/N)? ", 'Y', 'N' ) == 'Y' )
{
if( InAndOut.GetLetterFromUser( "Same setup (Y/N)? ", 'Y', 'N' ) == 'Y' ) return p_Same;
return p_New;
}
return finish;
}
void Look_outAround( Rooms_available* r )
{
byte message = 0, o;
for( int x = 0; x < max_Exits; x++ )
{
o = theCave.getRoom( r->getExit( x ) )->conntains();
message += ( ( wump & o ) + ( bat & o ) + ( pit & o ) );
}
if( message & wump ) InAndOut.message( " You smell something terrible nearby." );
if( message & pit ) InAndOut.message( " You feel a cold wind blowing from a nearby Caves_availablern." );
if( message & bat ) InAndOut.message( " You hear a rustling." );
}
bool checkExits( int e )
{
for( int x = 0; x < max_Exits; x++ )
if( e == exits[x] ) return true;
return false;
}
void getInput()
{
if( InAndOut.GetLetterFromUser( " Shoot or Move (S/M)? ", 'S', 'M' ) == 'M' )
{
int e = InAndOut.GetNumberFromUser( "Where to? " ) - 1;
if( checkExits( e ) ) Set_PLAYER( e );
else InAndOut.message( " Arrggh! --- You cannot go there! " );
}
else
{
do
pathLen = InAndOut.GetNumberFromUser( " Number of Rooms_availables (1-5)? " );
while( pathLen < 1 || pathLen > Path_Length );
for( unsigned i = 0; i < pathLen; i++ )
{
arrowPath[i] = InAndOut.GetNumberFromUser( "Room #" ) - 1;
if( i <= 1 || arrowPath[i] != arrowPath[i - 2]) conntinue;
InAndOut.message( " Arrows aren't that crooked! - Please, try another Rooms_available. " );
i--;
}
Shoot_around();
}
}
void Set_PLAYER( int pos )
{
if( playerPos < max_Rooms )
theCave.getRoom( playerPos )->Clear( player );
if( Hazards_around( pos ) ) return;
playerPos = pos;
Rooms_available* r = theCave.getRoom( playerPos );
r->Populate( player );
for( int x = 0; x < max_Exits; x++ )
exits[x] = r->getExit( x );
}
bool Hazards_around( int pos )
{
Rooms_available* r = theCave.getRoom( pos );
byte o = r->conntains();
if( wump & o )
{
InAndOut.message( " ...OOPS! Bumped a Wumpus! " );
if( Wumpus_inMove( pos ) )
{
InAndOut.message( " TSK TSK TSK - Wumpus got you! " );
gameOver = true; playerWins = false;
return true;
}
}
if( pit & o )
{
InAndOut.message( " YYYYIIIIEEEE!!!! Fell in pit! ");
gameOver = true; playerWins = false;
return true;
}
if( bat & o )
{
InAndOut.message( " ZAP -- Super bat snatch! Elsewhereville for you! " );
Set_PLAYER( rand() % max_Rooms );
return true;
}
return false;
}
bool Wumpus_inMove( int pos )
{
if( rand() % 100 < 75 )
{
Rooms_available* r = theCave.getRoom( Wumpus_inPos );
r->Clear( wump );
Wumpus_inPos = r->getExit( rand() % max_Exits );
theCave.getRoom( Wumpus_inPos )->Populate( wump );
}
return ( pos == Wumpus_inPos );
}
void Init_GAME( gResult gr )
{
InAndOut.message( " HUNT THE wump --------------- " );
theCave.Clear(); gameOver = false; arrowsCnt = maximum_Arrows;
if( gr == p_New )
{
saved[S_player] = rand() % max_Rooms;
Set_PLAYER( saved[S_player] );
saved[S_bat1] = Fill_ROOM( bat ); saved[S_bat2] = Fill_ROOM( bat );
saved[S_pit1] = Fill_ROOM( pit ); saved[S_pit2] = Fill_ROOM( pit );
Wumpus_inPos = saved[S_wump] = Fill_ROOM( wump );
}
else
{
Set_PLAYER( saved[S_player] ); Wumpus_inPos = saved[S_wump];
theCave.getRoom( Wumpus_inPos )->Populate( wump );
theCave.getRoom( saved[S_bat1] )->Populate( bat );
theCave.getRoom( saved[S_bat2] )->Populate( bat );
theCave.getRoom( saved[S_pit1] )->Populate( pit );
theCave.getRoom( saved[S_pit2] )->Populate( pit );
}
}
int Fill_ROOM( object c )
{
int i; Rooms_available* r;
do
{
i = rand() % max_Rooms;
r = theCave.getRoom( i );
}
while( r->conntains() );
r->Populate( c );
return i;
}
void Print_INSTRUCTIONS()
{
if( InAndOut.GetLetterFromUser( "Instructions (Y/N)? ", 'Y', 'N' ) == 'N' ) return;
InAndOut.message( " Welcome to 'HUNT THE wump' The Wumpus lives in a Caves_available of 20 Rooms_availables: each Rooms_available has 3 tunnels leading to "
"other Rooms_availables. (Look at a Dodecahedron to see how this works, if you don't know what a dodecahedron is, ask someone) "
" HAZARDS: -------- Bottomless pits: ---------------- Two Rooms_availables have bottomless pits in them. "
"If you go there, you fall into the pit and lose! Super bats: ----------- Two other Rooms_availables have super bats. If you go there, "
"a bat grabs you and takes you to some other Rooms_available at random, which might be troublesome. Wumpus: ------- The Wumpus is not "
"bothered by the Hazards_around, he has sucker feet and is too big for a bat to lift. Usually he is asleep. Two things wake him up: "
"your entering his Rooms_available or your Shoot_arounding an arrow. If the Wumpus wakes, he has 75% chance to move one Rooms_available or 25% chance to stay "
"still. After that, if he is where you are, he eats you up and you lose! You: ---- Each turn you may move or Shoot_around a crooked arrow. "
"- Moving: you can move one Rooms_available (thru one tunnel) - Arrows: you have 5 arrows. You lose when you run out. Each arrow can go from "
"1 to 5 Rooms_availables, you aim by telling the computer the Rooms_availables #s you want the arrow to go to. If the arrow can't go that way (if no tunnel) "
"it moves at random to the next Rooms_available. If the arrow hits the Wumpus: you win, if the arrow hits you: you lose. "
" WARNINGS: -------- When you are one Rooms_available away from Wumpus or any other hazard, the computer says: Wumpus: 'You smell something "
"terrible nearby.' Bat: 'You hear a rustling.' Pit: 'You feel a cold wind blowing from a nearby Caves_availablern.' Press return to play..." );
InAndOut.Wait();
}
public:
void play()
{
playerPos = max_Rooms;
gResult gr = p_New;
Print_INSTRUCTIONS();
while( gr != finish )
{
Init_GAME( gr );
while( !gameOver ) { Look_out(); getInput(); }
gr = showResult( playerWins );
}
}
};
int main( int argc, char* argv[] )
{
srand( static_cast<unsigned>( time( NULL ) ) );
Wumpus_in hw; hw.play();
return 0;
}
error list
10:1: error: 'connst' does not name a type In member function 'int InAndOut::GetLetterFromUser(std::string, int, int)'
: 23:10: error: 'std::istream' has no member named 'Clear' At global scope:
61:11: error: 'max_Exits' was not declared in this scope In member function 'int Rooms_available::getExit(int)':
52:31: error: 'exits' was not declared in this scope In member function 'void Rooms_available::setExit(int, int)':
56:32: error: 'exits' was not declared in this scope At global scope:
90:34: error: 'max_Rooms' was not declared in this scope In constructor 'Caves_available::Caves_available()':
73:28: error: 'max_Rooms' was not declared in this scope
73:52: error: 'max_Exits' was not declared in this scope
76:1: error: 'Rooms_availables' was not declared in this scope In member function 'void Caves_available::Clear()':
83:21: error: 'max_Rooms' was not declared in this scope
84:1: error: 'Rooms_availables' was not declared in this scope In member function 'Rooms_available* Caves_available::getRoom(int)':
87:45: error: 'Rooms_availables' was not declared in this scope At global scope:
96:10: error: declaration of 'InAndOut Wumpus_in::InAndOut' [-fpermissive]
13:7: error: changes meaning of 'InAndOut' from 'class InAndOut' [-fpermissive]
98:61: error: 'max_Exits' was not declared in this scope
98:83: error: 'Path_Length' was not declared in this scope
98:103: error: 'saved' was not declared in this scope In member function 'void Wumpus_in::Look_out()':
107:21: error: 'max_Exits' was not declared in this scope In member function 'void Wumpus_in::Shoot_around()':
123:17: error: 'max_Exits' was not declared in this scope
124:24: error: 'arrowPath' was not declared in this scope
126:9: error: 'max_Exits' was not declared in this scope
126:42: error: 'arrowPath' was not declared in this scope In member function 'void Wumpus_in::Look_outAround(Rooms_available*)':
167:21: error: 'max_Exits' was not declared in this scope In member function 'bool Wumpus_in::checkExits(int)':
180:21: error: 'max_Exits' was not declared in this scope
181:10: error: 'exits' was not declared in this scope In member function 'void Wumpus_in::getInput()':
197:33: error: 'Path_Length' was not declared in this scope
201:1: error: 'arrowPath' was not declared in this scope
202:49: error: 'conntinue' was not declared in this scope In member function 'void Wumpus_in::Set_PLAYER(int)':
212:17: error: 'max_Rooms' was not declared in this scope
221:21: error: 'max_Exits' was not declared in this scope
222:1: error: 'exits' was not declared in this scope In member function 'bool Wumpus_in::Hazards_around(int)':
251:22: error: 'max_Rooms' was not declared in this scope In member function 'bool Wumpus_in::Wumpus_inMove(int)':
264:37: error: 'max_Exits' was not declared in this scope
267:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] In member function 'void Wumpus_in::Init_GAME(gResult)':
273:48: error: 'maximum_Arrows' was not declared in this scope
277:1: error: 'saved' was not declared in this scope
277:7: error: 'S_player' was not declared in this scope 277:
28: error: 'max_Rooms' was not declared in this scope
279:7: error: 'S_bat1' was not declared in this scope
279:41: error: 'S_bat2' was not declared in this scope
280:7: error: 'S_pit1' was not declared in this scope
280:41: error: 'S_pit2' was not declared in this scope
281:22: error: 'S_wump' was not declared in this scope
285:13: error: 'saved' was not declared in this scope
285:19: error: 'S_player' was not declared in this scope
285:53: error: 'S_wump' was not declared in this scope
287:24: error: 'S_bat1' was not declared in this scope
288:24: error: 'S_bat2' was not declared in this scope
289:24: error: 'S_pit1' was not declared in this scope
290:24: error: 'S_pit2' was not declared in this scope In member function 'int Wumpus_in::Fill_ROOM(object)':
299:14: error: 'max_Rooms' was not declared in this scope In member function 'void Wumpus_in::play()':
330:13: error: 'max_Rooms' was not declared in this scope In member function 'Rooms_available* Caves_available::getRoom(int)':
87:66: warning: control reaches end of non-void function [-Wreturn-type]
can you please help fixing error thank you
Explanation / Answer
Line 10 - give a data type with const. Based on your code it should probably be 'const unsigned int'
Line 23 - the function name is 'clear' not 'Clear'
Line 96 - the name of variable should not be same as name of class. make it InAndOut in_and_out, also change it to in_and_out on lines 104, 105, 106, 109, 110
Line 202 - it is 'continue' not 'continnue'
These fixes should solve all the errors
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.