Main
Open Files
while there is data
read in next data
process next data
print final report
Main
Open Files
Read in next data
while there is data
process next data
Read in next data
print final report
int main() {
string productName;
float priceA, priceB;
int quantity;
bool valid;
float totalCost = 0;
float totalSave = 0;
ifstream fileA, fileB;
OpenFiles(fileA, fileB);
GetData(fileA, fileB, productName, priceA, priceB, quantity, valid);
while (valid) {
ProcessData(productName, priceA, priceB, quantity, totalCost, totalSave);
GetData(fileA, fileB, productName, priceA, priceB, quantity, valid);
}
CloseFiles(fileA, fileB);
FinnalReport(quantity, valid);
return 0
}
OpenFiles
Input: None
Output: Two file streams
a bool that indicates if the file streams are valid or not.
Get file names
Open first file
Open the second file
Set the flag to indicate that the files are valid.
set valid to false
repeat
Prompt for file name
attempt to open file
until a file is open
read in the first data file name
read in the second data file name
if both file names were read in successfully
set valid to true
close the configuration file
set flag to false open the file if the file was opend successfully set the flag to true
Set valid to false
Get data from the first file
Get data from the second file
If both are successful
set valid to true
set success to false
Get the item name
Get the item price
Get the item quantity
if successful
set success to true
Compute price difference
Compute Savings
Add savings to total savings
Compute total cost
Add cost to total cost
Print data line