#### Archived

This topic is now archived and is closed to further replies.

# Help With Functions

## Recommended Posts

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:
  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);
}  
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

##### Share on other sites
The compiler thinks:

''return num1(sqrt(num2))+(num1+num2);''

is a function call. Remove the ''num1'' bit and it should ''do something''

##### Share on other sites
I tried it out on mine and all it says is that getch() and sqrt() are undecalred. What are you using to compile?

##### Share on other sites

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);

##### Share on other sites
In:
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

##### Share on other sites
lol

Guess I typed too slowly.

Gamer-Insight.com

##### Share on other sites
Hmm, I added a ''*'' after the first num1 and that did the trick. BTW I''m using Borland C++Builder..

##### Share on other sites
Wow, I go to type my reply and 5 other people reply in the mean-time. Thanks for all the help.

##### Share on other sites
BTW, to the AP: include < math.h >, this is where sqrt () is defined, and include < stdio.h > for getch ().

[edited by - Melraidin on June 6, 2002 10:34:44 AM]

##### Share on other sites
Actually it is conio.h you should include to use getch().

##### Share on other sites
No its not...

_________________________________________________________________________
Can someone be nice and help me on my way to be the next Hideo Kojima?
Thought So...

##### Share on other sites
Hideo Kojima is a genius. No one can just ''become'' the next one.

• ### Forum Statistics

• Total Topics
628337
• Total Posts
2982164

• 9
• 24
• 9
• 9
• 13