Error 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 Learn more c++ error cannot be used as a function about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges error expression cannot be used as a function c++ Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each cannot be used as a function mathematica 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 the distance between two points cannot be used as a function arduino 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 asked Feb 7 '14 at 1:24
Time Cannot Be Used As A Function
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 perhaps (x1-x2)^2) is the "expression" and (y1-y2) is taken as a function call argum
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
Expression Cannot Be Used As A Function Arduino
Us Learn more about Stack Overflow the company Business Learn more about hiring variable cannot be used as a function developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the arduino function Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error: cannot be used as a http://stackoverflow.com/questions/21617609/error-expression-cannot-be-used-as-a-function function up vote 0 down vote favorite I just started learning C++ and wrote this : #include using namespace std; void sumtype (double sum) { if (sum>0) cout<<"P"<>a; cout<<"input value of b: "; http://stackoverflow.com/questions/27033677/error-cannot-be-used-as-a-function cin>>b; cout<<"sum= "<right below the namespace, but i think the problem relates to the use of the variable rather than a http://www.cplusplus.com/forum/beginner/72524/ declaration 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include #include using namespace std; double pwr(double https://bytes.com/topic/c/answers/965719-variable-cannot-used-function-error co2); int main( ) { double loan_hand, int_rate, face_value, monthly_payment, time_period, int_month, co1, co2, mp1, loan_amount; cout<< "Please enter amount in hand?\n"; cin >> loan_hand; cout<< "Please enter the interest rate?\n"; cin >> int_rate; cout << "Please enter the time period in months.\n"; cin >> time_period; int_month=int_rate/12; cannot be monthly_payment=loan_hand/time_period; co1=monthly_payment/int_month; co2= pow(1-(1+int_month, time_period(-1)); loan_amount=co1*co2; cout << "you will need a loan with a face value" << loan_amount; system("PAUSE"); return EXIT_SUCCESS; } Using a dev C++ compiler, the variable time_period appears to be considered a function and I'm not sure why. I know this is simple and appreciate any clear or concise answer, or a track to cannot be used find as such. Thank You Jun 4, 2012 at 4:45pm UTC Stewbond (2805) time_period is declared as a double. Therefore time_period(-1) is incorrect. Try either co2= pow(1-1+int_month, time_period-1); or co2= pow(1-1+int_month, time_period); or co2= pow(1-1+int_month, -1); depending on what you are trying to do. Last edited on Jun 4, 2012 at 4:49pm UTC Jun 4, 2012 at 4:46pm UTC Zhuge (4639) You are putting parentheses after it like its a function, so the compiler is complaining that it isn't. If you want multiplication, use the * symbol. Jun 4, 2012 at 4:48pm UTC Disch (13766) Also you have mismatched parenthesis. Jun 4, 2012 at 4:50pm UTC Lowest0ne (1536) You're only passing one argument to pow(), it needs two: double x = pow(2.0, 3); // x = 8 Last edited on Jun 4, 2012 at 4:50pm UTC Topic archived. No new replies allowed. C++ Information Tutorials Reference Articles Forum Forum BeginnersWindows ProgrammingUNIX/Linux ProgrammingGeneral C++ ProgrammingLoungeJobs Home page | Privacy policy© cplusplus.com, 2000-2016 - All rights reserved - v3.1Spotted an error? contact us
Post your question and get tips & solutions from a community of 418,506 IT Pros & Developers. It's quick & easy. "variable cannot be used as a function" error P: 1 cpsc122 I'm writing a very simple program, but I keep getting the same error, no matter what I do. What is it that is going wrong? It says I can't use the variable as a function. Here is my code: #include using namespace std; int what; int main() { int what; cout << what(9,3,17) << endl; } int what(int x, int y, int z) { if(x>y && x>z) return x; if(y>x && y>z) return y; if(z>x && z>y) return z; else return 0; } I feel like its a simple fix... help! Feb 19 '16 #1 Post Reply Share this Question 1 Reply Expert Mod 5K+ P: 8,904 weaknessforcats Starting from the top of the program, the first thing the compiler sees is: Expand|Select|Wrap|Line Numbers intwhat; The next thing the compiler sees is: Expand|Select|Wrap|Line Numbers intmain() { intwhat; This is a second variable named what but this one is local to main(). The int what outside of main is completely blocked by this local one. Then the compiler sees: Expand|Select|Wrap|Line Numbers cout<> Sign in to post your reply or Sign up for a free account. Similar topics How to fix "assigned a value that is never used " error? Classic ASP page error ActiveX component cannot create object error Page Cannot Be Displayed error for long running process in asp.net 2.0 ASP.NET Page cannot be displayed error basic auth causes page cannot be displayed error Cannot delete file from webserver...... process cannot access style error Website Page Cannot be Found Error HELP: Page cannot be displayed error (Page is there!) Cannot lock file error "Cannot Quit" error in application when shutting down WinNT 4.0 Browse more C / C++ Questions on Bytes Question stats viewed: 547 replies: 1 date asked: Feb 19 '16 Follow this discussion BYTES.COM © 2016 Formerly "TheScripts.com" from 2005-2008 About Bytes | Advertise on Bytes | Contact Us Sitemap | C / C++ Answers Sitemap | C / C++ Insights Sitemap Follow us to get the