Thread: enum question

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    enum question

    //Please consider the following



    #include <iostream>

    using namespace std;
    typedef unsigned short USHORT;
    enum ERR_CODE { SUCCESS, ERROR };
    /* would ERR_CODE be kind of a type that tells the ERR_CODE Factor function the values that it can return? In turn telling the function that it can return the "type" of ERR_CODE which are either the value of SUCCESS which is zero or the value of ERROR which is one*/

    ERR_CODE Factor(USHORT, USHORT&, USHORT&);

    int main()
    {
    USHORT number, squared, cubed;
    ERR_CODE result;

    cout << "Enter a number (0 - 20): ";
    cin >> number;

    result = Factor(number, squared, cubed);

    if (result == SUCCESS)
    {
    cout << "number: " << number << "\n";
    cout << "square: " << squared << "\n";
    cout << "cubed: " << cubed << "\n";
    }
    else
    cout << "Error encountered!!\n";
    int x; cin>>x;
    return 0;
    }

    ERR_CODE Factor(USHORT n, USHORT &rSquared, USHORT &rCubed)
    {
    if (n > 20)
    return ERROR; // simple error code
    else
    {
    rSquared = n*n;
    rCubed = n*n*n;
    return SUCCESS;
    }
    }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    Yes, Factor function should return ERROR or SUCCESS.

    At the end of your code where you do
    int x; cin >> x;
    You could also do
    cin.ignore(100,'\n');
    This will wait for the user to press enter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Question on Enum
    By markcls in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 08:19 AM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Enum question
    By Bill 101 in forum C Programming
    Replies: 4
    Last Post: 10-31-2002, 12:33 AM