term does not evaluate to a function taking 0 arguments [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I had try to compile this code but it shows this error "term does not evaluate to a function taking 0 arguments"
I'm completely new to programming so please help me out here.
For reference, the problem function seems to be:
void traps_rand()
{
while (player!=treasure)
srand((unsigned)time(0));
xt1=(rand %6()+1);
xt2=(rand %6()+1);
xt3=(rand %6()+1);
yt1=(rand %8()+1);
yt2=(rand %8()+1);
yt3=(rand %8()+1);
...
...
...

I'm pretty sure this is what you want if you are trying to generate a random number between 1-6:
xt1 = rand() % 6 + 1;
The statement above executes the function rand (as noted by the parentheses), then does modulo 6 on the result before adding 1.
Your original statement:
xt1=(rand %6()+1);
is attempting to invoke the function "6" and use that as the modulus with the address of rand. Then add 1. It hits as error because there is no function named 6. You can't name functions starting with numbers anyway.

Change rand %6()+1 to rand() %6 + 1. It looks like you are using a variable named rand and calling a function named 6(), but what you really want is to call rand() and mod it by 6 (+1).

Related

SAS Assignment Statement without even sign [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm studying for a SAS certification exam, and I came across an unexplained behavior. Note the data step below:
data D;
A+1;
A+1;
A+1;
run;
Question 1: Why this step does not result in error?
Question 2: Why a variable A is created, and its value is 3 and not missing?
Question 3: Why when I change + for - , it results in error?
I have searched about it and i couldn't find nothing, even in SAS documentation
A+1 is sum statement initially A or anything in that form is automatically set to 0 and in your second line of code it becomes 0 +1 = 1 then this value is in A is retained that is A becomes 1 and then when you add 1 in your 3 line of code becomes 2 and then 3. There is nothing of sort is there for -, so it errors when you do A-1, becomes A is not defined, where as in A +1 A is automatically set to 0. Below is the documentation for Sum statement
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm.
Please see in below comment of #longfish explains to do the samething for -1, you need to do A+-1
That is a SUM statement. The syntax is
variable + expression ;
That is why replacing the + with - did not work. It no longer followed the pattern above. If you want to subtract then negate the expression.
variable + - (expression) ;

C++ : How to arrange 4 values in an ascending order? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hello I know it may be a beginners question but I need help.
I need to compare between 4 values added by the user and arrange them in am ascending order by using a function that takes 2 inputs and return the smaller one. I know it can be done by arrays but I must not do it. I already have the function but I don't know how to use to do the trick without having a very long code. Thanks
This seems to me to be an obvious "homework question," so let me answer it cryptically in order to maybe push you in the right direction.
First, the hint: divide and conquer.
Second hint: the "Towers of Hanoi" problem.
You have a function that can compare two values. Okay, then: "four elements" can be viewed as "two groups of two values each." Given that either of the two input to your comparison-function can be the result obtained by a nested call to the same function . . . you can, indeed, solve this problem, in one line of code, without using arrays.
I'm trying here to "teach you to fish," so I'm not handing you the fish on a platter.
If you know c++ then you can use sort function. But for this you have to include algorithm as:
#include <algorithm>
and sort function will be used as:
sort(array, array+N);
where array is the array name and N is the size of array.After this operation you will get a sorted array in ascending order and return first element.Now the function will look like as:
int smallest(int *array) {
int size = sizeof(array) / sizeof(array[0]);
sort(array, array+size);
return (array[0]);
}
And now call this function from main()

C++ Function Prototype? [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 7 years ago.
Improve this question
I had this on a test this week and got it wrong. I asked the professor for help and he said we'd go over it next Thursday. I really don't want to wait that long. Can any one on here walk me through it?
Perform the task specified by the following statements:
Write the function prototype for function "doit" that takes an integer array parameter "list" and an integer "size" parameter and returns a boolean value.
Thanks in advance for any help
bool doit(int list[], int size);
The function doit takes an array of integers as first parameter, and the size of the array (which is an integer) as second parameter. It returns a boolean (true or false).
This sort of function prototype is typically used to access each element of the array within a for loop (with size as terminating condition). The boolean return value could inform of the presence or absence of some value in the array for example, or if some work could or could not be performed.
A little bit of help is there :
RETURN_TYPE FUNCTION_NAME (ARGUMENT1_TYPE ARGUMENT1,ARGUMENT2_TYPE ARGUMENT2);
It's not a big deal , it's just a prototype :)
I wrote the answer and removed it, u should try looking for the answer in the internet :)
Here you go:
+ doit(list : int[], size : int) : boolean

Function with one input behaving different after first call [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I need help with a problem regarding exponential smoothing in C++
The smoothing follows this equation :
newValue = inputSignal*smoothFactor + (1-smoothFactor)*oldValue
My function is supposed to only have one input parameter, that is the inputSignal parameter (the smoothFactor can be declared within the function and is not subject of the problem) and one output parameter, that is the newValue.
Now the issue I am having is that the FIRST calculation is missing an oldValue, since the oldValue is the preceding newValue in the first function call.
So the oldValue has to equal the first inputSignal in the first function call.
That means my function needs to behave different in its first call than every following call. I can solve this if I declare a global i=0 parameter and count up i++ after the first call. This however is NOT a function independent of outside circumstances, which it should be.
I was able to solve the problem with the i=0 and i++ global variables, but fail to find a solution without this.
You can use a local static variable in the function (cf this question). Local static variables are initialized exactely once on the first invocation of the method. So you can use this:
double smooth(double inputSignal) {
static double oldValue = inputSignal; // Executed only once on first invocation
double newValue = inputSignal*smoothFactor + (1-smoothFactor)*oldValue;
oldValue = newValue; // Store it for next invocation
return newValue;
}

c++ error: term does not evaluate to a function taking 1 arguments [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 8 years ago.
Improve this question
I'm getting the error 'term does not evaluate to a function taking 1 arguments' on the following line in my code:
steerToSpiralRefPoint(m_CentrePos);
But I'm not sure why this is... Is it that the function will only take 1 argument as a parameter, but since the 'm_centrePos' variable holds more than 1 attribute, the function is effectively receiving several parameters?
I have defined 'steerToSpiralRefPoint' with the line:
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData aHeloData);
'm_CentrePos' has been assigned the value 'cCentrePos' at the start of this file ('cCentrePos' is a variable of type 'CCoordinate', which has a number of attributes- latitude, longitude, altitude, etc).
'CDirectOverflyItem's also has a number of attributes- ground speed, wind speed, wind angle, etc.
Can anyone point out to me why I'm getting this error, and how I should correct it?
This expression
steerToSpiralRefPoint(m_CentrePos);
is a postfix expression of a function call. However as it follows from your post steerToSpiralRefPoint is not a function (or function pointer) but a pointer to an object. If you want to assign a value to the pointer then you have to write
steerToSpiralRefPoint = m_CentrePos;
Or if there is an operator function for this type then the code should look as
( *steerToSpiralRefPoint )( m_CentrePos );
And this construction
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData );
is also invalid. You may not use qualifiers before variables in expressions. They may be used only in declarations.
It seems that the issue was that I was trying to pass the wrong data type into the parameter- it was expecting a 'CHeloData', but I was trying to give it a 'CCoordinate'.