> Discrete Optimization > Food Manufacturing 2: Using Logical Constraints > Solving the Problem

The following statement solves the problem to optimality:

      if (cplex.solve()) {

These lines (the action of the if-statement) display the solution:

         cout << " Maximum profit = " << cplex.getObjValue() << endl;
         for (IloInt i = 0; i < nbMonths; i++) {
            IloInt p;
            cout << " Month " << i << " " << endl;
            cout << "  . buy   ";
            for (p = 0; p < nbProducts; p++) {
               cout << cplex.getValue(buy[i][p]) << "\t ";
            }
            cout << endl;
            cout << "  . use   ";
            for (p = 0; p < nbProducts; p++) {
               cout << cplex.getValue(use[i][p]) << "\t ";
            }
            cout << endl;
            cout << "  . store ";
            for (p = 0; p < nbProducts; p++) {
               cout << cplex.getValue(store[i][p]) << "\t ";
            }
            cout << endl;
         }
      }
      else {
         cout << " No solution found" << endl;