This program should search for an 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. My problem is I can't properly search through all the elements. I've tested it throughly and all my set and get functions are working properly, its my loop thats the problem. I've walked through this in my head, and verbally but I can't see whats wrong. I think my pride is getting in the way so I need help. Output given at the bottom.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
#include "invoiceheader.h"
#define MAX_INVOICES 10000
#define EXIT_CODE 0
#define SKIP_CODE 1
int main()
{
Invoice *Invoices = new Invoice[MAX_INVOICES];
int invoiceNum;
int qtyShipped;
int partNum;
string partDescrip;
float unitPrice;
string editChoice;
bool done = true;
bool found = true;
do
{
for(int i=0; i<MAX_INVOICES; i++)
{
cout << "\nType an Invoice number you would like to search for"
<< " or (" << EXIT_CODE << " to exit): ";
cin >> invoiceNum;
// Check for the exit code
if(invoiceNum == EXIT_CODE)
{
done = false;
break;
}
else
{
if(invoiceNum == Invoices[i].getInvoiceNum())
{
cout << "\nDoes anything need editing? (y or n): ";
cin >> editChoice;
if(editChoice == "y")
{
cout << "\nCurrent contents of invoice " << invoiceNum
<< ":";
Invoices[i].printInvoiceData();
cout << "\n\nEnter new quantity shipped (" << SKIP_CODE
<< " to skip): ";
cin >> qtyShipped;
if(qtyShipped != SKIP_CODE)
Invoices[i].setQtyShipped(qtyShipped);
cout << "\nEnter new part number (" << SKIP_CODE
<< " to skip): ";
cin >> partNum;
if(partNum != SKIP_CODE)
Invoices[i].setPartNum(partNum);
/*cout << "\nEnter new part description (" << SKIP_CODE
<< " to skip): ";
cin.ignore(1,'\n');
getline(cin, partDescrip);
if(partDescrip != SKIP_CODE)
Invoices[i].setPartDecription(partDescrip);*/// Stuck
cout << "\nEnter new unit price (" << SKIP_CODE
<< " to skip): ";
cin >> unitPrice;
if(unitPrice != SKIP_CODE)
Invoices[i].setUnitPrice(unitPrice);
cout << "\nHere is the new invoice: ";
Invoices[i].printInvoiceData();
}
}
else
{
cout << "\nSorry, no Invoices of " << invoiceNum
<< " found.";
found = false;
break;
}
}
}
} while(done != false);
Output without editing:
Enter an Invoice Number (or 0 to exit):12
Enter Quantity Shipped: 32
Enter Part Number: 45
Enter Part Description: This is for the engine.
Enter Unit Price: 23.76
Enter an Invoice Number (or 0 to exit):2
Enter Quantity Shipped: 45
Enter Part Number: 2
Enter Part Description: This is for the transmission.
Enter Unit Price: 45.34
Enter an Invoice Number (or 0 to exit):0
Type an Invoice number you would like to search for or (0 to exit): 2
Sorry, no Invoices of 2 found.
Type an Invoice number you would like to search for or (0 to exit): 1
Sorry, no Invoices of 1 found.
Type an Invoice number you would like to search for or (0 to exit): 12
Does anything need editing? (y or n): n
Type an Invoice number you would like to search for or (0 to exit): 12
Sorry, no Invoices of 12 found.
Type an Invoice number you would like to search for or (0 to exit): 0
Press any key and <enter> to exit
Output with editing:
Enter an Invoice Number (or 0 to exit):14
Enter Quantity Shipped: 12
Enter Part Number: 56
Enter Part Description: This is a test.
Enter Unit Price: 45.67
Enter an Invoice Number (or 0 to exit):0
Type an Invoice number you would like to search for or (0 to exit): 14
Does anything need editing? (y or n): y
Current contents of invoice 14:
Invoice Number: 14
Quantity Shipped: 12
Part Number: 56
Part Description: This is a test.
Unit Price: $45.67
Sales Tax Rate: 5%
Sales Tax Amount: 0.27
Shipping Cost: $5.00
Total Cost: $553.31
Enter new quantity shipped (1 to skip): 1
Enter new part number (1 to skip): 24
Enter new unit price (1 to skip): 4.35
Here is the new invoice:
Invoice Number: 14
Quantity Shipped: 12
Part Number: 24
Part Description: This is a test.
Unit Price: $4.35
Sales Tax Rate: 5.00%
Sales Tax Amount: 0.03
Shipping Cost: $5.00
Total Cost: $57.23
Type an Invoice number you would like to search for or (0 to exit): 14
Sorry, no Invoices of 14 found.
Type an Invoice number you would like to search for or (0 to exit): 0
Press any key and <enter> to exit