Try not to use
using namespace std
Try not to useusing namespace std
.<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case here. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to "possible loss of data." This is usually remedied by casting thestd::time()
return to anunsigned int
.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass one to a function as it would decay into a pointer. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case here. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to "possible loss of data." This is usually remedied by casting thestd::time()
return to anunsigned int
.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass one to a function as it would decay into a pointer. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case here. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to "possible loss of data." This is usually remedied by casting thestd::time()
return to anunsigned int
.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass one to a function as it would decay into a pointer. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case here. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to possible data"possible loss of data." This is usually remedied by casting thestd::time()
return to anunsigned int
.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass themone to functionsa function as thatit would deprecate them to pointersdecay into a pointer. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to possible data loss.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass them to functions as that would deprecate them to pointers. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case here. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to "possible loss of data." This is usually remedied by casting thestd::time()
return to anunsigned int
.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass one to a function as it would decay into a pointer. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce errors from the lack of casting. Justwarnings corresponding to be on the safe sidepossible data loss.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass them to functions as that would deprecate them to pointers. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
and pass it to that function as an argument.I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
I don't know how high your warnings are turned up, but your
std::srand()
may produce errors from the lack of casting. Just to be on the safe side, callstd::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass them to functions as that would deprecate them to pointers. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }
<stdlib.h>
is a C library. Use<cstdlib>
for C++.These shouldn't be global:
int xRan; int choicei = 12; int choicej = 12;
As you're using
xRan
in another function, initialize it inmain()
only:int xRan = rand() % 15 + 1;
and pass it to that function as an argument.
I also don't see why
choicei
andchoicej
are initialized to 12. If there's a reason for that, there should be a comment specifying that. Since it looks needless, just declare them inmain()
closely in scope with the input:cout << "Enter The Row Number Less Than 10!" << endl; int choicei; // declare here cin >> choicei;
cout << "Enter The Column Number Less Than 10!" << endl; int choicej; // declare here cin >> choicej;
On another note,
choicei
andchoicej
are not good names. What arei
andj
? One would assume they have to do with simple loop counters, but this doesn't seem to be the case. Consider something likerowNumberChoice
andcolNumberChoice
.I don't know how high your compiler warnings are turned up, but your
std::srand()
may produce warnings corresponding to possible data loss.If these warnings become present, call
std::srand()
like this:// if you're using C++11, use nullptr instead of NULL std::srand(static_cast<unsigned int>(std::time(NULL));
In C++, prefer to use standard containers over C-style arrays. You especially shouldn't pass them to functions as that would deprecate them to pointers. It's best to avoid this in C++.
I recommend using
std::array
, if you're using C++11. As 2D, it would be initialized like this:std::array<std::array<char>, 10>, 10> gameBoard;
As @nvuono mentioned, you could have row and column constants so that minimal updating is needed. You could then have this:
const unsigned int rows = 10; const unsigned int cols = 12; std::array<std::array<char>, rows>, cols> gameBoard;
To pass this 2D array to functions:
// you may use a typedef to "rename" this type for less typing // name should be capitalized as it is a type typedef std::array<std::array<char>, rows>, cols> Board; // pass as const-ref as the board shouldn't be modified void displayBoard(Board const& gameBoard) { }