1 Vase 3 Vessels game in C++ Here is the premise:




  Three women robbed a gentleman of a vase, containing 24 ounces of
  balsam. Whilst running away they met a glass-seller, of whom they
  purchased three vessels. On reaching a place of safety they wished to
  divide the booty, but found that their vessels contained 5, 11, and 13
  ounces respectively. How could they divide the balsam into equal
  portions?
  
  Basically you have to get the Vase = 8, Vessel2 =8, and Vessel3 = 8.
  
  But it has to be in this format:

Pour 1 2

Show

Pour 1 3

Show

Pour 2 4

Show

Pour 4 1

Show

...




"Show" means display the contents of the jars
"Pour 1 2" means pour as much of the contents of container 1 into container 2 as possible


The pour function should protect itself from bad commands:

Pour 1 1
Pour 0 3
Pour 1 5 // where there are only 4 jars


I finished the program but I was wondering if anyone thinks I could improve the performance or formatting, and how. In particular, the protection in the range because it kinda seems like it messes with the flow since the user no longer enters pour. They just enter the source and destination, and if they decide to enter the pour source destination, the while loop goes into space.



#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cassert&gt;
using namespace std;

const int VASE = 0;
const int VESSEL1 = 1;
const int VESSEL2 = 2;
const int VESSEL3 = 3;


const int capacity[] = { 24, 5, 11, 13 };
const string names[] = { "VASE", "VESSEL 1", "VESSEL 2", "VESSEL 3" };
int volume[] = { 24, 0, 0, 0 };

void display(int count);
void pour(int source, int destination);
bool isEmpty(int container);
bool isFull(int container);

int main()
{
int count = 0;

cout &lt;&lt; "----------The commands available are pour from source to destination or show the contents of all the jars.-----------" &lt;&lt; endl;
cout &lt;&lt; "\nFOR EXAMPLE:" &lt;&lt; endl;
cout &lt;&lt; "'Pour 1 2' means pour as much of the contents of container 1 into container 2 as possible." &lt;&lt; endl;
cout &lt;&lt; "'Show' means display the contents of the jars." &lt;&lt; endl;

cout &lt;&lt; "The starting contents of the jars are ";
display(count);

do
{
    int source, destination;
    string command;
    cout &lt;&lt; "\nPLEASE ENTER COMMAND NUMBER " &lt;&lt; count + 1&lt;&lt; endl;
    cin &gt;&gt; command;
    cin.ignore();

    if (command == "Pour" || command == "pour" || command == "POUR")
    {
        cin &gt;&gt; source &gt;&gt; destination;
        pour(source, destination);
    }
    else if (command == "Show" || command == "show" || command == "SHOW")
        display(count);
    else
        cerr &lt;&lt; "YOU HAVE NOT ENTERED A VALID COMMAND." &lt;&lt; endl;

    count++;
} while ((volume[VASE] != volume[VESSEL2]) || (volume[VESSEL2] != volume[VESSEL3]));
system("pause");
return 0;
}

void pour(int source, int destination)
{
    while (source &lt; VASE || source &gt;VESSEL3 || destination &lt; VASE ||                  destination &gt; VESSEL3)
{
    cerr &lt;&lt; "You have enterered a wrong source or a wrong destination." &lt;&lt; endl;
    cout &lt;&lt; "Please note that the range of both source and destination is from 0-3." &lt;&lt; endl;
    cout &lt;&lt; "Please enter source and destination now i.e for example (1 3) " &lt;&lt; endl;
    cin &gt;&gt; source &gt;&gt; destination;
}
while (!isEmpty(source) &amp;&amp; !isFull(destination))
{
    volume[source]--;
    volume[destination]++;
}
}
 bool isEmpty(int container)
 {
     return volume[container] == 0;
 }
 bool isFull(int container)
 {
    return volume[container] == capacity[container];
 }

void display(int count)
{
    cout &lt;&lt; ": ";
    for (int index = VASE; index &lt;= VESSEL3; index++)
         cout &lt;&lt; volume[index] &lt;&lt;  " : ";
    cout &lt;&lt; endl;
}
A couple of things that could help.

A menu and a switch block will simplify the main function.

A class to represent a vessel with quantity and a state that would be empty, full or partially full, would help clean up the rest of the code.

Make the menu options a '1' or a '2'.  This way you don't have to rely on the case.  

And instead of explaining to the user how to enter the parameters, simply ask them which vessel to pour from and which vessel to pour to, and validate and correct, their answers before calling the functions.

Here's an example of using a class a menu and a switch block.  Some of the functions will need to be fleshed out, but you can easily see how mush easier it is to follow the flow of the program this way:

class Vessel
{
    map&lt;char , string&gt; states =
    { {
        {{'E',"Empty"}},
        {{'P',"Partial"}},
        {{'F',"Full"}}
    } };
    int _quantity = 0;
    int _capacity = 0;
public:
    Vessel( int capacity );
    string GetState();
    int GetCapacity();
    int GetQuantity();
    void SetQuantity( int volume );
    void Pour( Vessel other );
};
void DisplayVessels( map&lt;int , Vessel&gt; vessels )
{
    cout &lt;&lt; "The state of the vessels:\n";
    cout &lt;&lt; setw( 4 ) &lt;&lt; "Size\t" &lt;&lt; setw( 5 ) &lt;&lt; "State\t" &lt;&lt; setw( 4 ) &lt;&lt; "Used\n";
    int counter = 1;
    for ( auto v : vessels )
    {
        cout &lt;&lt; counter++ &lt;&lt; setw( 4 ) &lt;&lt; v.second.GetCapacity() &lt;&lt; '\t' &lt;&lt; setw( 5 ) &lt;&lt; v.second.GetState() &lt;&lt; '\t' &lt;&lt; setw( 4 ) &lt;&lt; v.second.GetQuantity() &lt;&lt; '\n';
    }
}
void Pour( map&lt;int , Vessel&gt;&amp; vessels )
{

}
int main()
{
    map&lt;int , Vessel&gt; vessels =
    { {
        {{24,Vessel( 24 )}},
        {{5,Vessel( 5 )}},
        {{11,Vessel( 11 )}},
        {{13,Vessel( 13 )}}
    } };
    cout &lt;&lt; "Welcome to the Vessel Game\n"
        &lt;&lt; "Three women stole a vase full of balsam(24 oz.)\n"
        &lt;&lt; "During their get away they meet a glass merchant and buy 3 vessels from him.\n"
        &lt;&lt; "Upon reaching a safe place to divvy up their spoils, they discover that the vessels are of odd sizes(5,11, and 13 oz.)\n"
        &lt;&lt; "Your job is to figure out how to divide the balsam into 3 vessels each containing 8 oz.\n\n";
    vessels[24].SetQuantity( 24 );
    char choice;
    bool done = false;
    while ( !done )
    {
        cout &lt;&lt; "1. Pour\n"
            &lt;&lt; "2. Display\n"
            &lt;&lt; "0. Quit\n";
        cin &gt;&gt; choice;
        switch ( choice )
        {
            case '1':
                Pour( vessels );
                break;
            case '2':
                DisplayVessels( vessels );
                break;
            case '0':
                done = true;
                break;
            default:
                cout &lt;&lt; "Wrong choice.\n";
                break;
        }
    }

}