codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Help needed with C++ functions  speedstream at 23:29 on Sunday, July 03, 2005
 

I am a beginner in C++ programming & I use Microsoft visual studio.net 2003 as my compiler.

I wrote the following simple program for area of a triangle

#include<iostream>

int main()

{

int breadth,height;

int area;

std::cout<< "Enter the breadth";
std::cin>>breadth;
std::cout<< "Enter the height";
std::cin>>height;

area = TriangleArea(breadth,height);

std::cout<<"Area of the triangle is:"<<area;

return 0;

}
int TriangleArea(int b,int h)

{
return 0.5 (b*h);

}


On debugging in showed the following errors

c:\My Documents\Visual Studio Projects\C++\Function\Area of triangle.cpp(17): error C3861: 'TriangleArea': identifier not found, even with argument-dependent lookup

c:\My Documents\Visual Studio Projects\C++\Function\Area of triangle.cpp(26): error C2365: 'TriangleArea' : redefinition; previous definition was a 'formerly unknown identifier'

How do I solve the following errors? Do I need to include any header files?

Thanks



<Added>

I have figured out my error.....forgot to define function at the beginning.

<Added>


#include<iostream>

int TriangleArea(int b,int h);//function prototype...that's what I missed in the above program

int main() // rest of the code as above

{

int breadth,height;
------
-------


  Re: Help needed with C++ functions  Rashakil Fol at 02:14 on Wednesday, July 06, 2005
 

Why are you using integers? If somebody inputs the numbers 3 and 5, the area is 7.5.

  Re: Help needed with C++ functions  speedstream at 21:36 on Wednesday, July 06, 2005
 

I used intergers only for my convinence.You can ofcourse change the variable type to float.

  Re: Help needed with C++ functions  korax at 06:49 on Tuesday, August 02, 2005
 

Have you tried using a forward declaration my friend? In other words:

putting:
int TriangleArea(int, int);
before the main function?

Try that out. I guess it should help.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007