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( "\n\n-----------------------------------\n"
);
in_and_out.message( "You are in Rooms_available #" );
in_and_out.message( playerPos + 1 );
in_and_out.message( "\nTunnels 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( "\n OUCH! Arrow got you!\n" ); return;
}
}
in_and_out.message( "\n Missed!\n\n" );
if( --arrowsCnt == 0 )
{
in_and_out.message( "\n You run out of arrows...\n" );
gameOver = true; playerWins = false;
return;
}
Wumpus_inMove( playerPos );
}
gResult showResult( bool pw )
{
if( pw ) in_and_out.message( "\n AHA! You got the Wumpus!\n HEE HEE
HEE - The Wumpus'll getcha next time!!\n\n" );
else in_and_out.message( " HA HA HA - You lose!\n\n" );
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( "\nYou smell
something terrible nearby." );
if( message & pit ) in_and_out.message( "\nYou feel a cold wind
blowing from a nearby Caves_availablern." );
if( message & bat ) in_and_out.message( "\nYou 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( "\n\nShoot 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( "\nArrggh! --- You cannot go there!\n\n"
);
}
else
{
do
pathLen = in_and_out.GetNumberFromUser( "\nNumber 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( "\nArrows aren't that crooked! - Please, try
another Rooms_available.\n\n" );
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( "\n ...OOPS! Bumped a Wumpus!\n\n" );
if( Wumpus_inMove( pos ) )
{
in_and_out.message( "\n TSK TSK TSK - Wumpus got you!\n" );
gameOver = true; playerWins = false;
return true;
}
}
if( pit & o )
{
in_and_out.message( "\n YYYYIIIIEEEE!!!! Fell in pit!\n");
gameOver = true; playerWins = false;
return true;
}
if( bat & o )
{
in_and_out.message( "\n ZAP -- Super bat snatch! Elsewhereville for
you!\n\n" );
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( "\n\n\n\nHUNT THE wump\n---------------\n" );
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( "\n\nWelcome to 'HUNT THE wump'\n\nThe Wumpus
lives in a Caves_available of 20 Rooms_availables: each
Rooms_available has 3 tunnels leading to\n"
"other Rooms_availables. (Look at a Dodecahedron to see how this
works, if you don't\nknow what a dodecahedron is, ask
someone)\n"
"\n\n HAZARDS:\n --------\n\nBottomless
pits:\n----------------\nTwo Rooms_availables have bottomless pits
in them.\n"
"If you go there, you fall into the pit and lose!\n\nSuper
bats:\n-----------\nTwo other Rooms_availables have super bats.\nIf
you go there, "
"a bat grabs you and takes you to some other Rooms_available at
random,\nwhich might be troublesome.\n\nWumpus:\n-------\nThe
Wumpus is not "
"bothered by the Hazards_around, he has sucker feet and is too
big\nfor a bat to lift.\nUsually he is asleep.\nTwo things wake him
up: "
"your entering his Rooms_available or your Shoot_arounding an
arrow.\nIf the Wumpus wakes, he has 75% chance to move one
Rooms_available or 25% chance to stay\n"
"still.\nAfter that, if he is where you are, he eats you up and you
lose!\n\nYou:\n----\nEach turn you may move or Shoot_around a
crooked arrow.\n"
"- Moving: you can move one Rooms_available (thru one tunnel)\n-
Arrows: you have 5 arrows. You lose when you run out.\n Each arrow
can go from "
"1 to 5 Rooms_availables, you aim by telling the computer the\n
Rooms_availables #s you want the arrow to go to.\n If the arrow
can't go that way (if no tunnel) "
"it moves at random to the \n next Rooms_available.\n If the arrow
hits the Wumpus: you win, if the arrow hits you: you lose.\n"
"\n\n WARNINGS:\n --------\nWhen you are one Rooms_available away
from Wumpus or any other hazard, the computer says:\nWumpus: 'You
smell something "
"terrible nearby.'\nBat: 'You hear a rustling.'\nPit: 'You feel a
cold wind blowing from a nearby Caves_availablern.'\n\n\n\nPress
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
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( "\n\n\n\nHUNT THE wump\n---------------\n" );
Change to :-
in_and_out.message( "\n\n\n\nHUNT THE wump\n---------------\n" );
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] );
fix error #include <time.h> #include <iostream> #include <sstream> typedef unsigned char byte; enum gResult { finish,...
#include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...
Merge Sort: Time Complexity: O(n log(n)) #include "stdafx.h" #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; void combine(int *a, int low, int high, int mid) { int i, j, k, c[100000]; i = low; k = low; j = mid + 1; while (i <= mid && j <= high) { if (a[i] < a[j]) { c[k] = a[i]; k++; i++; } else { ...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
Getting this error. [Error] expected ';' after class definition #include <iostream> #include <cstdlib> #include <ctime> #include <conio.h> using namespace std; int sum=0; class Coin { int sideUp; public: Coin(int value) { toss(value); }; void toss(int value); } void Coin::toss(int value) { if(rand() %100<=50) { sum+=value; cout<<"\n You got a head. Value "<<value<<" added!!"; } else { cout<<"\n You got a tail. No value added"; } } int main() { int temp; cout<<"\n Quarter = 25 cents\n Dime = 10 cents...
There is a problem with thecode. I get the error messages " 'board' was not declared in this scope", \src\TicTacToe.cpp|7|error: expected unqualified-id before ')' token| \src\TicTacToe.cpp|100|error: expected declaration before '}' token| Here is the code #ifndef TICTACTOE_H #define TICTACTOE_H #include class TicTacToe { private: char board [3][3]; public: TicTacToe () {} void printBoard(); void computerTurn(char ch); bool playerTurn (char ch); char winVerify(); }; ************************************ TicTacToe.cpp #endif // TICTACTOE_H #include "TicTacToe.h" #include #include using namespace std; TicTacToe() { for(int i =...
***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...
I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...
BST.cpp #include "BST.h" #include "BT-visualize.h" #include <assert.h> #include <stdio.h> #include <string.h> #include <string> // Implement the following five methods // inserts val into BST rooted at x and returns the tree's new root BTnode * insert(BTnode * x, int val) {} // returns true iff target in tree rooted at x bool search(BTnode * x, int target) {} // Find the maximum value of a tree rooted at x int findmax(BTnode * x) {} // Find the manimum value of...
Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node { int data; node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() { struct node*head=NULL; char commands; int value; ...
Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() { int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false; srand(seed); // call the getRandom function below tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...