some problems in running cpp functions programs

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

using namespace 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.

There's a tutorial on this site which you could learn from:
http://www.cplusplus.com/doc/
Thanks a lot, this helped me a lot;
i took it from my class lecture notes,


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!
Topic archived. No new replies allowed.