Ok so I prompt the user for invoices (Invoice Number, Quantity Shipped, Part Number, Part Description, and Unit Price) until the user gets tired and enters an Invoice Number of 0 for an invoice. After the user enters an Invoice Number of 0, he should not be prompted for any additional invoice info, and the program should enter an “edit mode”. In edit mode, the user is prompted for an invoice number. The program should search for that invoice, display all its current information, and allow the user to change and store each of the values originally entered. To exit “edit mode” (and the program) the user can enter an Invoice Number of 0.
Problem 1: My problem is trying to think of a way to exit the loop incase they enter 0 first or 0 anytime after the first. Am I doing it right with the do..while or is there some other way?
Problem 2: I'm trying to think of a good search algorithm, should I use sequential search?

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

#include "invoice.h"

#define MAX_INVOICES 10000
#define EXIT_CODE       0

int main()
   Invoice *Invoices = new Invoice[MAX_INVOICES];
   int    invoiceNum;
   int    qtyShipped;
   int    partNum;
   string partDescrip;
   float  unitPrice;
   bool   done = true;

      bool done = true;
      cout << "\nEnter an Invoice Number (or " << EXIT_CODE << " to exit):";
      cin  >> invoiceNum;
      if(invoiceNum == 0)
         done = false;
      for(int i=0; (i<MAX_INVOICES || done != false); i++)
         cout << "\nEnter an Invoice Number (or " << EXIT_CODE << " to exit):";
         cin  >> invoiceNum;
         cout << "\nEnter Quantity Shipped: ";
         cin  >> qtyShipped;
         cout << "\nEnter Part Number: ";
         cin  >> partNum;
         cout << "\nEnter Part Description: ";
         cin  >> partDescrip;
         cout << "\nEnter Unit Price: ";
         cin  >> unitPrice;

   } while (done != false);

Your exit method should work, although a more effective method is, after the cin >> invoiceNum line, have a check against EXIT_CODE, and if it does exist, use a break; command to leave the for loop, then it should jump out of the while loop as well. There's a few STL that have some good sorting/search algorithms. I think <algorithm> is the header file you'll need. (Or just write one yourself)

This article has been dead for over six months. Start a new discussion instead.