int doSomething(int num1, int num2); //function prototypes
int main(int argc, char* argv[])
{
int num1, num2;
cout << "Enter number 1: ";
cin >> num1;
cout << "Enter number 2: ";
cin >> num2;
cout << endl;
int ans = doSomething(num1, num2); //assigns what
//the function returns
cout << "The answer is: " << ans << "."; //to ans
getch();
return 0;
}
int doSomething(int num1, int num2)
{
return num1(sqrt(num2))+(num1+num2);
}
Help With Functions
I''m very new to C++, and I''m having some problems that I can''t solve by looking in my text book. I can''t figure out what''s wrong with my simple program. Here''s the source code:
When I try to compile this, my compiler gives me the error "[C++ Error] Learning1.cpp(34): E2314 Call of nonfunction." Any help here? I''ve never come across that error before and I don''t know how to fix it.. Thanks!
-Kevinator
The compiler thinks:
''return num1(sqrt(num2))+(num1+num2);''
is a function call. Remove the ''num1'' bit and it should ''do something''
''return num1(sqrt(num2))+(num1+num2);''
is a function call. Remove the ''num1'' bit and it should ''do something''
<a href="http://www.purplenose.com>purplenose.com
June 06, 2002 09:05 AM
I tried it out on mine and all it says is that getch() and sqrt() are undecalred. What are you using to compile?
Your problem is this line:
You are trying to use num1 as if it were a function, which it clearly isn''t. You probably mean
return num1(sqrt(num2))+(num1+num2);
You are trying to use num1 as if it were a function, which it clearly isn''t. You probably mean
return num1*(sqrt(num2))+(num1+num2);
In:
It thinks you''re calling a function called num1();... Look at how you have it set up. You need some sort of operator between num1 and the opening paren ''(''. That''ll fix it. ex:
and you don really need the parens and could just use:
Gamer-Insight.com
return num1(sqrt(num2))+(num1+num2);
It thinks you''re calling a function called num1();... Look at how you have it set up. You need some sort of operator between num1 and the opening paren ''(''. That''ll fix it. ex:
return num1*(sqrt(num2))+(num1+num2);
and you don really need the parens and could just use:
return num1*sqrt(num2)+num1+num2;
Gamer-Insight.com
Hmm, I added a ''*'' after the first num1 and that did the trick. BTW I''m using Borland C++Builder..
Wow, I go to type my reply and 5 other people reply in the mean-time. Thanks for all the help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement