0

Function

What is the difference between these two function and which of these ist better or more useful #include <iostream> using namespace std; float circle(float radius, float area) { area = radius * radius * 3.14; return area; } int main() { float radius, area; cout << "what is the raduis of the circle" << '\t'; cin >> radius; cout<<"the area of the circle is" << '\t'<< circle(radius,area); return 0; } #include <iostream> using namespace std; float circle(float); int main() { float radius, area; cout << "what is the raduis of the circle" << '\t'; cin >> radius; area = circle(radius); cout << "the area of the circle is" << '\t' << area << endl; return 0; } float circle(float radius) { return radius * radius * 3.14; }

28th Nov 2019, 11:49 AM
fabio di vincenzo
fabio di vincenzo - avatar
1 Odpowiedź
+ 2
In the first function you have this second parameter `area` that is never used so there's no reason to include it. I think I know what you were trying to do but you'll learn about that later (it's about pointers). The second function seems fine. That's how I would write it.
28th Nov 2019, 1:07 PM
Schindlabua
Schindlabua - avatar