Error And Cannot Be Used As A Function
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business c++ error cannot be used as a function Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Error Expression Cannot Be Used As A Function C++
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like cannot be used as a function mathematica you, helping each other. Join them; it only takes a minute: Sign up Error: expression cannot be used as a function? up vote -4 down vote favorite I created a quick method in my program to compute
Cannot Be Used As A Function Arduino
the distance between two points using the distance formula, here's the code: #include #include using namespace std; int distanceFormula(int x1, int y1, int x2, int y2) { double d = sqrt((x1-x2)^2(y1-y2)^2); return d; } it gives me a compiler error on the line where I declare the "d" variable saying that "error: expression cannot be used as a function". What does this mean? and what am I doing wrong? c++ compiler-errors share|improve this question time cannot be used as a function asked Feb 7 '14 at 1:24 LoreleiRS 15225 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote Be careful, (x1-x2)^2 will not do an exponent of 2 here. See http://www.cplusplus.com/reference/cmath/pow/. Second, you probably forgot a + in your expression: int distanceFormula(int x1, int y1, int x2, int y2) { double d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)); return d; } share|improve this answer edited Jan 11 at 17:28 answered Feb 7 '14 at 1:27 Mr_Pouet 1,17531331 1 Ah! thank you! I was laying this out during math class and it totally slipped my mind about the power function, thank you so much –LoreleiRS Feb 7 '14 at 1:30 1 Just in case you are interested, ^ (XOR) is actually an operator in C/C++. See cplusplus.com/doc/boolean –Mr_Pouet Feb 7 '14 at 1:41 Why not change the return type of the function to double? –ForceBru Jan 11 at 17:31 @ForceBru Though I'm sure OP wasn't thinking about casting the returned result, I went with an answer that would respect his original method signature. But in many real life scenarios you might want to return double yes :) –Mr_Pouet Jan 12 at 16:15 add a comment| up vote 1 down vote The compiler error is because 2(y1-y2) is invalid syntax. In this case 2 (or perha
here for a quick overview of the site Help Center Detailed answers to any questions you
Expression Cannot Be Used As A Function Arduino
might have Meta Discuss the workings and policies of this site
Variable Cannot Be Used As A Function
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or arduino function posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of http://stackoverflow.com/questions/21617609/error-expression-cannot-be-used-as-a-function 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “cannot be used as a function” error up vote -2 down vote favorite Please have a look at the following code #include #include #include using namespace std; bool multiple(int,int); void isMul(vector); vector http://stackoverflow.com/questions/12771933/cannot-be-used-as-a-function-error numbers; int enterNumber = 0; int main() { cout << "Enter numbers (-1 to stop entering; -2 to exit)" << endl; cin >> enterNumber; while(true) { if(enterNumber==-1) { isMul(numbers); break; } else { numbers.push_back(enterNumber); cin >> enterNumber; } } } bool multiple(int number1, int number2) { if(number2%number1 == 0) { return true; } else { return false; } } void isMul(vector numbers) { cout << "First Number" << setw(10) << "Second Number" << setw(10) << "isMultiplication" << endl; for(size_t size=0;sizeNew Topic/Question Reply 2 Replies - 17629 Views - Last Post: 03 March 2009 - 07:25 PM Rate Topic: #1 thwhisler New D.I.C Head Reputation: 1 Posts: 11 Joined: 20-February 09 error: cannot be used a function Posted 03 March http://www.dreamincode.net/forums/topic/90425-error-cannot-be-used-a-function/ 2009 - 06:54 PM I am writing a program that will calculate the determinates of 2 by 2 or 3 by 3 matrixes. This is what i currently have: #include #include using namespace std; double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9); double det2(double b1, double b2, double b3, double b4); double a1, a2, a3, a4, a5, a6, a7, a8, a9; int main() cannot be { int cType; double det; cout << "What is the size of the matrix? "; cin >> cType; cout << "\nEnter the terms going across\n"; if (cType == 2) { cin >> a1; cin >> a2; cin >> a3; cin >> a4; det = det2(a1, a2, a3, a4); } else if (cType == 3) { cin >> a1; cin >> a2; cin >> a3; cin >> a4; cin >> a5; cin >> a6; cin >> a7; cin cannot be used >> a8; cin >> a9; det = det3(a1, a2, a3, a4, a5, a6, a7, a8, a9); } else { cout << "Not a supported option.\n"; exit(1); } cout << "The determinant is " << det << endl; return 0; } double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9) { double det1, det2, det3, det5; det1 = (a1 * det2(a5, a6, a8, a9)); det2 = (a4 * det2(a2, a3, a8, a9)); det3 = (a7 * det2(a2, a3, a5, a6)); det5 = det1 - det2 + det3; return det5; } double det2(double b1, double b2, double b3, double b4) { double det4; det4 = (b1 * b4) - (b3 * b2); return det4; } When i compile it, I get the following errors: determinant.cpp: In function ‘double det3(double, double, double, double, double, double, double, double, double)': determinant.cpp:62: error: ‘det2' cannot be used as a function determinant.cpp:63: error: ‘det2' cannot be used as a function determinant.cpp:64: error: ‘det2' cannot be used as a function What am I doing wrong? Is This A Good Question/Topic? 1 Back to top MultiQuote Quote + Reply Replies To: error: cannot be used a function #2 polymath D.I.C Addict Reputation: 53 Posts: 670 Joined: 04-April 08 Re: error: cannot be used a function Posted 03 March 2009 - 07:21 PM You cannot name your