# C++ Endless Output

**URL:** <https://forum.kirupa.com/t/c-endless-output/283877>\
**Category:** programming\
**Created:** [March 12, 2009, 1:49am UTC](https://forum.kirupa.com/t/c-endless-output/283877 "2009-03-12T01:49:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Exodar](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@Exodar](https://forum.kirupa.com/u/Exodar)\
**Post date:** [March 12, 2009, 1:49am UTC](https://forum.kirupa.com/t/c-endless-output/283877/1 "2009-03-12T01:49:11Z")

</div>

For the following code, a number is inputed and the cube of that number is displayed. When anything other than a number is inputed, for example a letter, the message “Please Enter a number.” should be displayed once. The problem is that the same message is being displayed endlessly and I have no idea why this is.

If I take out “return main()” from the main() function, then I don’t get this endless display of the same message when a number is not inputed. However, I want the program to repeat so that users can enter as much numbers as they want. Does anyone know a solution to this?

```auto
//cubes a user entered number
#include <iostream>
using namespace std;

double cube(double n); //function prototype
double user;

int main()
{
        cout << "Enter the number you want to cube: "; //ask user to input number
        
        if ( !(cin >> user) ) {
            cout << "Please Enter a number." << endl;
        } else {
        cout << "The cube of " << user << " is " << cube(user) << "." << endl; //displaying the cubed number
        }

        return main();
}

double cube (double n) //function that cubes the number
{
        return n*n*n; // cubing the number and returning it
}

```
