I wrote this code to get the Area of circle, but i don't know whats wrong with it, that i got many errors. Can you please fix these errors, and write me in detail, where i did mistakes (please mention the mistakes) . I'm learning functions. And my compiler is BloodShed Dev-C++ . i will be very thankful, if you will help me out.
cout << "Please enter the outer radius value";
cin >> rad1;
cout << "Please enter the outer radius value";
cin >> rad2;
ringArea = circleArea (rad1) - circleArea (rad2);
cout<< "Area of the ring having inner radius " << rad2 << " and outer radius " << rad1 <<" is " << ringArea;
}
//////////////////////////////////////…
and the Errors are
6 C:\Dev-Cpp\include\c++\3.4.2\backward\io… from C:\CircleArea.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/io… from C:\CircleArea.cpp
6 C:\CircleArea.cpp from C:\CircleArea.cpp
C:\Dev-Cpp\include\c++\3.4.2\backward\ba… In function `int main()':
14 C:\Dev-Cpp\include\c++\3.4.2\backward\ba… `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
15 C:\Dev-Cpp\include\c++\3.4.2\backward\ba… `cin' undeclared (first use this function)
6 C:\CircleArea.cpp In file included from C:\CircleArea.cpp
6 C:\CircleArea.cpp At global scope:
40 C:\Dev-Cpp\include\c++\3.4.2\backward\io… `cout' is already declared in this scope
41 C:\Dev-Cpp\include\c++\3.4.2\backward\io… `cin' is already declared in this scope
C:\CircleArea.cpp In function `int main()':
8 C:\CircleArea.cpp redefinition of `int main()'
3 C:\Dev-Cpp\include\c++\3.4.2\backward\ba… `int main()' previously defined here
most efficient... least space occupied.
@mindfog:always main() need not have int.... different compilers work differently...
turbo c++ allows main(), void main() but dev c++ does not...
Your header module filename is wrong. It should be <iostream>. Also, you need to specify which parts of the standard namespace you're planning on using such as cout. You can do this by using the using directive. For example:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
using std::cout; // the 'std' is the identifier of the standard namespace.
int main( )
{
cout << "..." << endl;
// Optionally, you could do this:
std::cout << "..." << std::endl;
}
int must be main's return type-specifier. Don't forget to initialize objects (variables) before you use them. There's a difference between initialization and assignment.
Initialization: The operation that assigns a value to a variable at the point of declaration.
Assignment: The operation that assigns a value to a variable after declaration.
- main should always return an int.
- <iostream.h> should not be used (deprecated)
- <iostream> is standards compliant
- mindfrog's first reply has the best advice to the OP's problem.
@rambo1177:
Turbo C++ is extremely outdated.
I must use it because it is the one used in school, but even then it remains outdated.
using iostream.h won't work in modern compilers (MS VC++ for example)