1. ## functions

i am having trouble with the divide function in the main. any help would be great.

Code:
```#include <iostream>
#include "fun.h"
using namespace std;
double divide (double num1, double num2);
int main()

{
double a, b, c;									//declares variables
cout<<"Enter two numbers:";							//displays output
cin>>a>>b;									//gets input
cout<<endl;									//ends line

/**************************************
*  Adds the value of a and b          *
*  @param a  a double                 *
*  @param b  a double 	              *
*  @return   the sum of the two inputs*
**************************************/
cout<<"The sum of the two numbers is: " <<c;
cout<<endl;

/***************************************
*  Subtracts the value of a and b      *
*  @param a  a double                  *
*  @param b  a double 	               *
*  @return   the diff of the two inputs*
***************************************/
c=subtract(a,b);
cout<<"The difference of the two numbers is: " <<c;
cout<<endl;

/******************************************
*  Mutiplies the value of a and b         *
*  @param a  a double                     *
*  @param b  a double 	                  *
*  @return   the product of the two inputs*
******************************************/
c=multiply(a,b);
cout<<"The product of the two numbers is: " <<c;
cout<<endl;

/***************************************
*  Cubes the value of a and b          *
*  @param a  a double                  *
*  @param b  a double 	               *
*  @return   the cube of one input     *
***************************************/
c=cube(a);
cout<<"The cube of the first number is: " <<c;
cout<<endl;

/***************************************
*  Cubes the value of a and b          *
*  @param a  a double                  *
*  @param b  a double 	               *
*  @return   the cube of one  input    *
***************************************/
c=cube(b);
cout<<"The cube of the second number is: " <<c;
cout<<endl;

double divide (double num1, double num2)
{
double total;
total = num1 / num2;
}

return 0;
}```

2. Define that function outside of your main() function.
Ex:
Code:
```#include <iostream>
using namespace std;

void foo();

int main()
{
//
//
return 0;
}

void foo()
{
cout << "foo" << endl;
}```

3. is there any way to get this to work inside the main.

4. That would be non-function version
Code:
```int main()
{
// the rest of the code

double total;
total = num1 / num2;

return 0;
}```

5. is it possible to do this as a function in the main?

6. Originally posted by bj31t
is it possible to do this as a function in the main?
Nop, can't declare a function inside a function, including main

7. thanks for the help

8. You can write the function outside of main and call it from inside main like you called multiply, cube, etc. That is how it is normally done.

9. ## Right!

...That is how it is normally done.
Right! In fact, with most large programs, main() won't do anything except call other functions. You might have some "branching" logic (like if-statements and switch-statements), but all of your I/O, calculations, data manipulation, etc., would be done in functions.

10. Keyword: large programs Just to clarify.