so this is a checkout program. Hers my problem: the user enters 1 to enter checkout and then enters the PLU code followed by the weight of it or unit, then they have to choice to enter another PLU code or 0 to exit. Once the user enters 0 it displays the total cost and is suppose to then asks the user again to press 1 to checkout or 0 to exit,instead, it asks to enter the PLU code or 0 to exit. any thoughts on how i can fix this?

4011 BANANAS 1 0.49 123.2
4383 MINNEOLAS 1 0.79 187.3
3144 TANGERINES 1 1.19 135.5
4028 STRAWBERRIES_PINT 0 0.99 104
4252 STRAWBERRIES_HALF_CASE 0 3.99 53
4249 STRAWBERRIES_FULL_CASE 0 7.49 67

#include <iostream>
#include <string>
#include <fstream>
using namespace std;



struct storePro
{
   int PLUcode;
   string itemName;
   int itemType;
   double itemPrice;
   double itemLevel;
};
int main()
{


   fstream filename("theList.txt");
   storePro array[6];
   int o;

   //if (!filename.fail())
   {
      for (int o = 0; o < 6; o++)
      {

         filename >> array[o].PLUcode >> array[o].itemName >> array[o].itemType >> array[o].itemPrice >> array[o].itemLevel;

      }
      for (int o = 0; o < 5; o++)
      {
         cout << array[o].PLUcode << " " << array[o].itemName << " "
            << array[o].itemType << " " << array[o].itemPrice << " "
            << array[o].itemLevel << endl;
      }
   }


   cout<<" "<<endl;
   cout<<" " <<endl;
   int userChoice;


   cout << "Enter 1 to checkout or 0 to end checkout.";
   cin >> userChoice;

   do
   {

      if (userChoice == 1)
      {
         int count = 0;
         int PLU = 0;
         int userIn;
         float units;
         float sum = 0;


         do
         {
            bool found = false;
            PLU = 0;
            //PLU = -1;
            cout << "Please enter PLU number or 0 to leave.";
            cin >> userIn;

            if (userIn == 0)

            {
               break;
            }

            for (int o = 0; o < 6; o++)
            {
               if (array[o].PLUcode == userIn)
               {
                  PLU = o;
                  //invalid = o;
                  found = true;
                  break;
               }


            }

            if (!found)
            {
               cout << "PCU code was not found." << endl;
               cout << "Please enter PLU number or 0 to leave.";
               cin >> userIn;
               //break;
            }
            //PLU = 0;
            if (array[PLU].itemType == 1)
            {
               cout << "Pounds: ";
               count++;

            }
            else
            {
               cout << "Units: ";
               count++;
            }

            cin >> units;
            sum = sum + units + array[PLU].itemPrice;

         } while (userIn != 0);
         cout << "$"  << sum << endl;

      }
      else
      {
         return 0;
      }

   } while (userChoice != 0);

   return 0;
}

You just have to put

cout << "Enter 1 to checkout or 0 to end checkout.";
cin >> userChoice;

Inside the first do while

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.