This looks like C code, not C++. I would consider the following changes:
0.
Replace <stdio.h> with <cstdio>. (You can ignore this if you do 5 instead.)
1.
Put the variable declarations inside the function where they are used. You do not need them to be global. In fact, you should declare them on the first line where you use them, like this:
|
double answer = cube(input);
|
2.
The return type of main must be int, otherwise it's not valid C++.
3.
Do not use main() as a recursive function. Explicitly calling the main() function is not common practice. If you need to use recursion, make a new function for it.
4.
Get rid of the recursion. The program would be easier to read if you simply used a loop, like this:
1 2 3 4 5
|
bool again = true;
while (again) {
...
// update again from user input
}
|
5.
Use IO streams insted of printf/scanf. These functions are typically used in C, but are considered less safe than the newer stream operations. This way you get rid of all your format string confusion (e.g. %ld vs %f). Example:
1 2 3 4 5
|
#include <iostream>
// ...
std::cout << "Enter an integer value: ";
std::cin >> input;
|