What you're doing makes no sense. You've got an array of seven int values, and you're saying "this array of seven int values is to be set equal to this one, single int value". Makes no sense.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Until I can load up the program and see what is happening it is hard to follow your code. Just add code tags to what yu have will not indent the code as it needs to be.
In the function "shipPlacement" you define the array "ShipPlacement" as a 2D array. IMHO I would call this backwards. i would use the capital "S" for the function name and the lower case "s" for the variable name.
Anyway ShipPlacement[c]=((rand()%7)+1); "ShipPlacement" is a 2D array and you are only using one dimension to store your result. The reason this does not work is because the result of "rand" needs to be stored in the second dimension not the first.
"srand" should be near the beginning of main because you only need to call it once. Should your game play again as is "srand" would be called again when "shipPlacement" is called and the numbers may not be as random as you might think.
((rand() % 7) + 1) this will miss the number zero. This may work, but for an array that starts at zero you would be missing an entire row or column.
To set a 2D array you will need an outer for loop to control the row and the inner for loop, that you have, to control the columns.
Your compiler is either unable to use a newer C++ standard, or you haven't set the language standard to make constexpr available.
I don't use Eclipse, so I don't know what the problem might be.
never seen the std:: stuff.
using namespace std; will do that. It is considered a bad thing to do.
https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice.
You might want to learn about the C++ random library.
http://en.cppreference.com/w/cpp/numeric/random
srand()/rand() have serious drawbacks.
http://cpp.indi.frih.net/blog/2014/12/the-bell-has-tolled-for-rand/
As FurryGuy said "constextp" is from C++11 on, but "const" will work just as well. What this is likely saying is that your compiler and header files need upgraded to at least cover the C++11 standards.
In short the unsigned means that the variable can only hold positive numbers. This is useful because there are many functions that return an "unsigned int" and the subscript of any type of array can only have a positive number. Using "unsigned" just makes sure that what is going into the variable is a positive number.
const tells the compiler you, the programmer, won't be trying to change an object, a variable. If you do, the compiler slaps your hand and says, "no, no no."
Any use of the function is evaluated at compile-time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
constexprint factorial(int n)
{
return n <= 1 ? 1 : (n * factorial(n - 1));
}
int main()
{
// this is evaluated at compile-time, not run-time
int fact4 = factorial("A");
std::cout << "4!: " << fact4 << '\n';
}
Error C2664 'int factorial(int)': cannot convert argument 1 from 'const char [2]' to 'int'
Error (active) E0167 argument of type "const char *" is incompatible with parameter of type "int"
So you can find possible problems at compile-time instead of when your program is running.