wpe41.gif (23084 bytes)CIS3355: Business Data Structures
Fall, 2008
 

Program Controls

This is a simple program, which puts some additional controls on the previous program you wrote.

The last program allowed the user to enter 'illegal' choices (i.e., something other than '1' through '8'). You are to stop the user from doing that.

How??

As you will recall, your previous program had the section of code:

void main()
{
    char menuchoice;
    int intvalue1; intvalue2;
    float fvalue1, fvalue2

    displaymenu();
    cin >> menuchoice;
 

Which displayed the menu and got the user input. You should change this section of code to:

void main()
{
    char menuchoice;
    int intvalue1, intvalue2, legal;
    float fvalue1, fvalue2

    do
    {
         legal = 0;
         while (legal == 0)
         {
                displaymenu();
                cin >> menuchoice;
                legal = checkchoice(menuchoice);
         }

Notice you will have to change your function checkchoice so that it returns a value:

    A 0 (zero) if the choice is not in the specified range, and something else if it is.

You will also have to change function displaymenu to look like:
 

void displaymenu()
{
    cout << "Enter your choice:\n\n";
    cout << " 1. Add two integers\n";
    cout << " 2. Subtract an integer from another integer\n";
    cout << " 3. Multiply two integers\n";
    cout << " 4. Divide two integers\n";
    cout << " 5. Find the Quotient of two integers\n";
    cout << " 6. Find the Remainder of two integers\n";
    cout << " 7. Multiply two Real Numbers\n";
    cout << " 8. Divide two Real Numbers\n\n";
    cout << " 0. Quit this program\n\n";
    cout << "? ";
}

There is one additional choice, namely the last one:  cout << " 0. Quit this program\n\n";

This allows the user to continue rerunning the program until they decide to quit

How will this change the program?

Not really by much. You will notice that we started the program with a do statement. We know that a do ...while is an entry level check. The while component will go at the end of the main function, and will simply be:

    } while (menuchoice != '0');

The only caution I would give you is to watch your begin and end ellipses.

Have fun