Simple C Program to exhibit fuzzy behavior

Don't expect a lot from this program. It simply returns the results of a calculation by using a different formula each time. The end-user doesn't know the internal mechanism, so, to him it appears like a random behavior.

Last Reviewed and Updated on May 17, 2017
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Advertisement

Simple Program to exhibit fuzzy behaviour

Write a program that keeps asking the user to enter a number. But each time it keeps giving the output by a different formula. It asks the user to enter a number, and it displays either the cube or square or double of that number. Then it again asks the user to enter a number, and it displays either the cube or square or double of that number. It continues to behave in this fuzzy manner. Internally, you can keep some secret which determines the formula to be used for calculations. Don't use loops.

int main()
{

    int m = 0, n = 0, p = 0;

    int square = 0, cube = 0, twice = 0;

lblA:
    cout << "Enter a number: ";

    cin >> m;

    square = m * m;

    cout << "Square = " << square << endl;

    if(m < p)
    {

        goto lblB;

    }

    else
    {

        goto lblC;

    }

lblB:
    cout << "Enter a number: ";

    cin >> n;

    cube = n * n * n;

    cout << "Cube = " << cube << endl;

    if(n < m)
    {

        goto lblC;

    }

    else
    {

        goto lblA;

    }

lblC:
    cout << "Enter a number: ";

    cin >> p;

    twice = 2 * p;

    cout << "Twice = " << twice << endl;

    if(p < n)
    {

        goto lblA;

    }

    else
    {

        goto lblB;

    }

    return 0;

}


My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.



Creative Commons License
This Blog Post/Article "Simple C Program to exhibit fuzzy behavior" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2017-05-17.


Advertisement