0

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;
}
2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by bernardo.mclobo
0

You just have to put

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

Inside the first do while

Edited by bernardo.mclobo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.