Can any1 please fix this c++ source problem
/*Circle Are program
Calculates the area of a circle using the formula A=pi * r * r
Sonny Hinh, 1/23/08
#include <iostream.h>
int main()
{
cout << "-Calculate the area of a circle-" << endl;
cout << end;
cout << "Radius = " << 10 << endl;
cout << "Area = " << (3.14*10*10) << endl;
return 0;
}
Did you intend for the line:
cout<<end;
to really be:
cout<<endl;
i tried and it didn't work :<
and you email me a uncompiled answer?
sonnytsn1_@_gm_ai_l._co_m
I did a quick check using MS VS2005. The following compiles correctly. Changing the line:
cout<<endl;
to:
cout<<end;
gives a compile error
--------------------------------
Below compiles using VS2005
--------------------------------
#include <tchar.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "-Calculate the area of a circle-" << endl;
cout << endl;
cout << "Radius = " << 10 << endl;
cout << "Area = " << (3.14*10*10) << endl;
return 0;
}
missed the end
-------------------------
#include <tchar.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "-Calculate the area of a circle-" << endl;
cout << endl;
cout << "Radius = " << 10 << endl;
cout << "Area = " << (3.14*10*10) << endl;
return 0;
}
I guess the double blank lines caused the posting applet to clip the last two lines. Here they are finally, I hope.
--------------------
return 0;
}
Nope, for some reason the last lines which are not posting.
Anyway, the last lines are the same as your source.
To fix the C++ source problem, there are a few issues that need to be addressed:
1. Include Statements: The source code is missing the necessary include statement for the iostream library. Replace `#include <iostream.h>` with `#include <iostream>` to fix this issue.
2. Namespace: The code does not specify the namespace explicitly. Add `using namespace std;` after the include statements to fix this issue.
3. Cout Statements: The code is using the `cout` statement incorrectly. Replace `cout << end;` with `cout << endl;` to fix this issue.
Here is the corrected version of the code:
```cpp
#include <iostream>
using namespace std;
int main()
{
cout << "-Calculate the area of a circle-" << endl;
cout << "Radius = " << 10 << endl;
cout << "Area = " << (3.14 * 10 * 10) << endl;
return 0;
}
```
With these changes, the code should compile and run correctly, calculating and displaying the area of a circle with a radius of 10 units.