i am a new in C++, could anyone tell me error on this program.and How
can it be fixed
#include <iostream.h>
int main()
{
double p = 99;
double y;
y = fun (p);
cout << y;
return 0;
}
double fun (double p)
{
return p*p*p;
}
The obsolete header #include <iostream.h> suggests you have picked up some old, non-standard code.
In current C++ you'd need to fix a few things.
1. Use the up-to-date header <iostream> rather than <iostream.h>.
2. Declare the function fun() before you try to use it.
3. Add some code to allow the cout to be used. For now, the using statement will do, to get you started.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream> // modern standard header
usingnamespace std; // to allow use of std::cout
double fun (double p); // declare function prototype
int main()
{
double p = 99;
double y;
y = fun (p);
cout << y;
return 0;
}
double fun (double p)
{
return p*p*p;
}
If this code came from a book or a tutorial somewhere, I suggest you discard it as being out of date.
As a new to c/c++ I recommend you to take it slow as c can get very complicated and thus lead to errors that hard to detect. If you need help with it you can try using some programs such as checkmarx or others, sure those can help.
I still recommend learn as much as you can for better programming.
Good luck!