Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

fix error #include <time.h> #include <iostream> #include <sstream> typedef unsig

ID: 3575147 • Letter: F

Question

fix error


#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 };

const unsigned int 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 In_And_Out
{
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( unsigned 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( unsigned 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:
class In_And_Out in_and_out;
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 );
in_and_out.message( " ----------------------------------- " );
in_and_out.message( "You are in Rooms_available #" ); in_and_out.message( playerPos + 1 );
in_and_out.message( " Tunnels lead to Rooms_availables #: " );
for( unsigned int x = 0; x < max_Exits; x++ )
{
in_and_out.message( ( 1 + r->getExit( x ) ) );
in_and_out.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;
in_and_out.message( " OUCH! Arrow got you! " ); return;
}
}

in_and_out.message( " Missed! " );
if( --arrowsCnt == 0 )
{
in_and_out.message( " You run out of arrows... " );
gameOver = true; playerWins = false;
return;
}

Wumpus_inMove( playerPos );
}

gResult showResult( bool pw )
{
if( pw ) in_and_out.message( " AHA! You got the Wumpus! HEE HEE HEE - The Wumpus'll getcha next time!! " );
else in_and_out.message( " HA HA HA - You lose! " );

if( in_and_out.GetLetterFromUser( "Play again (Y/N)? ", 'Y', 'N' ) == 'Y' )
{
if( in_and_out.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( unsigned int x = 0; x < max_Exits; x++ )
{
o = theCave.getRoom( r->getExit( x ) )->conntains();
message += ( ( wump & o ) + ( bat & o ) + ( pit & o ) );
}

if( message & wump ) in_and_out.message( " You smell something terrible nearby." );
if( message & pit ) in_and_out.message( " You feel a cold wind blowing from a nearby Caves_availablern." );
if( message & bat ) in_and_out.message( " You hear a rustling." );
}

bool checkExits( int e )
{
for( unsigned int x = 0; x < max_Exits; x++ )
if( e == exits[x] ) return true;
return false;
}

void getInput()
{
if( in_and_out.GetLetterFromUser( " Shoot or Move (S/M)? ", 'S', 'M' ) == 'M' )
{
int e = in_and_out.GetNumberFromUser( "Where to? " ) - 1;
if( checkExits( e ) ) Set_PLAYER( e );
else in_and_out.message( " Arrggh! --- You cannot go there! " );
}
else
{
do
pathLen = in_and_out.GetNumberFromUser( " Number of Rooms_availables (1-5)? " );
while( pathLen < 1 || pathLen > Path_Length );

for( unsigned i = 0; i < pathLen; i++ )
{
arrowPath[i] = in_and_out.GetNumberFromUser( "Room #" ) - 1;
if( i <= 1 || arrowPath[i] != arrowPath[i - 2]) continue;
in_and_out.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(unsigned 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 )
{
in_and_out.message( " ...OOPS! Bumped a Wumpus! " );
if( Wumpus_inMove( pos ) )
{
in_and_out.message( " TSK TSK TSK - Wumpus got you! " );
gameOver = true; playerWins = false;
return true;
}
}

if( pit & o )
{
in_and_out.message( " YYYYIIIIEEEE!!!! Fell in pit! ");
gameOver = true; playerWins = false;
return true;
}

if( bat & o )
{
in_and_out.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 )
{
in_and_out( " 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( in_and_out.GetLetterFromUser( "Instructions (Y/N)? ", 'Y', 'N' ) == 'N' ) return;
in_and_out.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..." );
in_and_out.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

In member function 'void Wumpus_in::Shoot_around()':

125:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] In member function 'bool Wumpus_in::checkExits(int)':

182:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] In member function 'bool Wumpus_in::Wumpus_inMove(int)':

268:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] In member function 'void Wumpus_in::Init_GAME(gResult)':

273:57: error: no match for call to '(In_And_Out) (const char [35])'

286:59: error: invalid types 'const unsigned int[const unsigned int]' for array subscript

Explanation / Answer

Given error list warning doesn't explicitly affect your program. If you want to remove the warning than you use to change the datatypes of the given comparision in the warning but it doesn't affect the running program so warning are fine.As for last two error change the folowing the error will be removed

273:57: error: no match for call to '(In_And_Out) (const char [35])'

line 273:-

in_and_out( " HUNT THE wump --------------- " );

Change to :-

in_and_out.message( " HUNT THE wump --------------- " );

286:59: error: invalid types 'const unsigned int[const unsigned int]' for array subscript

line 286:-

Set_PLAYER( saved[S_player] );

Change to:-
saved[S_player] = rand() % max_Rooms;
Set_PLAYER( saved[S_player] );