Sales Exercise 02 any ideas..?

Hey everyone im working on this assignment for my c++ intro class what i need to do is..start my program like this:

** start of program ***
Enter filename("sales_01.txt"): sales_01.txt

61 10003 05-07-14 TB001 Toothbrush 1 1.00
61 10003 05-13-14 SB005 Bar_Soap 5 0.50

10003 Sales Rep Total $ 3.50 *

61 10005 05-01-14 MP070 Kitchen_Mop 2 10.00

10005 Sales Rep Total $ 20.00 *

61 10006 05-01-14 TB001 Tooth_Brush 4 1.00
61 10006 05-07-14 TP002 Tooth_Paste 23 1.12
61 10006 05-07-14 TP002 Mouthwash 13 0.98
61 10006 05-16-14 SB005 Bar_Soap 1 0.50

10006 Sales Rep Total $ 43.00 *

61 10009 05-19-14 SP008 Soap_Powder 238 1.89
61 10009 05-25-14 WF080 Floor_Wax 5 2.98

10009 Sales Rep Total $ 477.20 *

Sales Rep Grand Total $ 543.70 **

Run program again(y/n)?

by using a text file but I'm gettin a few identifier errors: any ideas..?? this is what my code looks like..:


// preprocessor directives
#include <iostream>
#include <string>
#include <fstream> // open()
#include <iomanip> // setw(), setiosflags()
using namespace std;

// Disable warning messages 4996.
#pragma warning( disable : 4996 )

/* Function: main() *************************************************
*
* application entry point
*/
int main(void)
{

/* declarations ***********************************************
declare program data (scope: local)
*/
// constants

// variables
// file identifiers
fstream inData; // input file variable name=inData
string filename;

// fields for file data
int recordCode;
int salesRep;
string dateOfSale;
string productCode;
string productDescription;
int quantitySold;
double unitPrice;
int amount = 0; // initialize numeric variables

// control break field
string previousLastName; //

// program total fields
// groupTotal is the accumulation of all amounts of one person.
// -each unique person is considered a group
// grandTotal is the accumulation of all groupTotals
int groupTotal = 0; // group subtotal by last name
int grandTotal = 0; // total of all groups

// program identifiers
string programLoop;
int returnStatus;

/* statements *************************************************
declare program instructions
*/
cout << "*** start of program ***" << endl;

// Step #1: initialize program loop variable & others
programLoop = "y";
returnStatus = 0;

// Step #2: do while program loop is Y or y
while(programLoop == "y" || programLoop == "Y")
{
// Step #3: get filename for user
cout << "Enter filename(\"SALES_01.txt\"): ";
cin >> filename;

cout << endl;

// Step #4: open the file
inData.open( filename.c_str(), ios::in );

// Step #5: if file open failure
if(!inData)
{
// Step #6 display file open failure message
cout << "<< Unable of open the file: " << filename << endl;
cin.get();

// Step #7 set return code to 1 (unsuccessful operation)
returnStatus = 1;
}
else
{
// Step #8 set return code to 0 (successful operation)
returnStatus = 0;

// Step #9 read the fields of first row from the file
inData >> recordCode;
inData >> salesRep;
inData >> dateOfSale;
inData >> productCode;
inData >> productDescription;
inData >> quantitySold;
inData >> unitPrice;

// Step #10 while not end of file
while(!inData.eof() )
{
// Step #11 save current value to previous value
previousLastName = lastName;

// Step #12 re-initialize group subtotal for new group
groupTotal = 0;

// Step #13 while not eof and current equal previous
while( !inData.eof() && previousLastName == lastName)
{
// Step #14 format & display the file fields
cout << fixed << showpoint << setprecision(2);
cout << left << setw(3) << recordCode;
cout << left << setw(6) << salesRep;
dateOfSale.insert(4, "-");
dateOfSale.insert(2, "-");
cout << right << setw(9) << dateOfSale;
cout << right << setw(6) << productCode;
cout << right << setw(16) << productDescription;
cout << right << setw(9) << quantitySold;
cout << fixed << setprecision(2) << right << setw(8) << unitPrice;
cout << endl;

// Step #15 accumulate group total
groupTotal += amount;

// Step #16 read fields of the next record
inData >> recordCode;
inData >> salesRep;
inData >> dateOfSale;
inData >> productCode;
inData >> productDescription;
inData >> quantitySold;
inData >> unitPrice;
} // end while not eof and current equal previous

cout << endl;

// Step #17 display group subtotals of an individual
cout << setw(30) << "Individual Total:";
cout << setw(10) << groupTotal;
cout << " *" << endl << endl;

// Step #18 accumulate grand total from group total
grandTotal += groupTotal;

} // end while not end of file

// Step #19 close the file
inData.clear();
inData.close();

// Step #20 display grand total
cout << right << setw(30);
cout << "Grand Total:";
cout << setw(10) << grandTotal;
cout<<" **"<<endl;

} // end if file open failure

// Step #21 reset for next file...
grandTotal = 0;

// Step #22 run program again?
cout << "\nRun program again(y/n)? ";
cin >> programLoop;
} // end do while program loop is Y or y

// Step #23 terminate the program
cout<<"*** end of program ***"<<endl;
cin.get();

// Step #24 return
return 0; // 0=successful


let me know what you guys think..thanks..
The compiler isn't finding a definition for lastName.

1
2
// Step #11 save current value to previous value
previousLastName = lastName;


prog.cpp:100:20: error: ‘lastName’ was not declared in this scope
previousLastName = lastName;
Topic archived. No new replies allowed.