2D Arrays - Creating virtual Creatures? (C++) [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Next, this is where it gets confusing. I have to create a virtual creature by storing a letter into a random position in the array (the array can be up to 20x20 in size). How would I go about doing that?
Nevermind, figured it out

While I don't intend to provide the answer to homework, here are some commands and concepts that should help you:
cin - to read input from the user
rand() % number - (see http://www.cplusplus.com/reference/cstdlib/rand/ for an example) to generate random numbers
You will probably want to make your array of type "char" instead of "int"
Here is a link to functions in C++ - http://www.cplusplus.com/doc/tutorial/functions/
Here is a link to operators in C++ (specifically you will want to use ==) - http://www.cplusplus.com/doc/tutorial/operators/
For example, to see if x is equal to y:
if(x == y)
{
cout << "x equals y!";
}

Related

Is there a way to enter a number through another number? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm taking a C++ class in school, (No experience with programming) so I realize that this is a very dumb question and also horribly worded but here it is:
Is there any way to enter 6-21 (As in 6 through 21) into a boolean expression? I've tried it like this:
if (regs = 6-21)
But it assumes that I'm trying to subtract. What I'm trying to ask is, is there a way to enter a number through another number? Is it even possible?
Here is how you do it:
if (regs >= 6 && regs <= 21) {
// some code
}
>= means "greater than or equal to".
<= means "less than or equal to".
&& means "and", as in "if this AND this is true".

C++ input value process as math function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I’m very new in C++ and I need your help. I want to use the input value as a mathematical function then print the result.
What i need is:
When user input: 2 +1 and hit Enter then output (cout>>)
should be your result is: 3 (the sum of 2 + 1)
The mathematical symbol could be + or * or / or -.
Could you please help me with some example?
Thanks in advance!
Search for "Reverse Polish notation" and implementation in C++

c++ binary value for indexed array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am extremely new to C++ so I'm probably asking a very trivial question, but if you could help that'd be great!
I have an array[n].
Indexed from 0 to some unknown value.
I need to access the index of the array, the n value but I need to do so in binary. I am intending to do a bit reversal on it.
So, if I have an array of 2048 points how do I represent the 1024 array in binary?
If you want to write a value in binary, you can do so in C++14 with
int my_binary_value = 0b01010101;
If you'd like to test a specific bit of an int, you can do that by masking it, i.e.
bool is_bit_4_set = my_binary_value & 0b00001000;

Why do we need fundamental data types in c++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
While revising for my test the thought came to my mind that why do we exactly need to give a variable a specific datatype? Can the our computers not differentiate between the character an integer values we store in variables? If they cant why?
Consider this simple example.
int i;
int j;
if (b)
{
i = 0;
}
else
{
i = 999999;
}
Where should j be placed in memory? Depending on a run-time condition, either a small or large number is stored in i. But space for j is needed before this point is reached, so i must have an established size. Therefore compiler needs to know its basic type and therefore size.

Reading numbers and unevaluated statements from a file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a general file which constructs certain shapes and I would like to read in the lines:
0 0 1
0 x(r) y(r)
where x and y are functions of r, which is a variable taken in as an argument to main, such as 2*r-4.
Then I need to read the columns downwards into arrays.
For columns with just numbers you can do something like:
file >> x[j];
However I am unsure how to get the expressions to be read into the program and then be evaluated and then be put into an array as a number.
I am having problems reading in columns with entries of different types. Ideally I would like each to be assigned like:
temp[0]=1;
temp[1]=2*r-4;
but I am not sure how to do this.
(I am not sure whether the function fscanf would work?)
You can read an entire line with file.getline(someString, maxLength). Then you can split the string so you have strings for x(r) and y(r). These strings need to be parsed as mathematical expressions. This question has good information on the subject for c++: Convert string to mathematical evaluation