Question: The code I ran was: #include #include #include #include using namespace std; int main ( ) { / / Open input and output files ifstream

The code I ran was:
#include #include #include #include using namespace std; int main(){// Open input and output files ifstream inputFile("inventory.txt"); // Input file ofstream outputFile("inventory_report.txt"); // Output file // Check if the file is opened successfully if (!inputFile){ cout "Error opening the input file!" endl; return 1; }// Variables to store data from the file string itemName; int numberOfUnits; double unitCost, totalValue, grandTotal =0; // Print header to the output file outputFile fixed setprecision(2); outputFile "Inventory Report For Jane Doe International Hardware" endl; outputFile "------------------------------------------------------" endl; outputFile setw(15) left "ITEM" setw(15) right "NUMBER OF UNITS" setw(10) "UNIT COST ($)" setw(15) "TOTAL VALUE ($)" endl; outputFile "------------------------------------------------------" endl; // Read data from input file and calculate the total value for each item while (inputFile >> itemName >> numberOfUnits >> unitCost){ totalValue = numberOfUnits * unitCost; grandTotal += totalValue; // Print each item in the formatted table outputFile setw(15) left itemName setw(15) right numberOfUnits setw(10) unitCost setw(15) totalValue endl; }// Print total inventory value, right aligned under TOTAL VALUE column outputFile "------------------------------------------------------" endl; outputFile setw(40) left "Inventory Total ($)" setw(15) right grandTotal endl; // Close the files inputFile.close(); outputFile.close(); cout "Inventory report generated successfully." endl; return 0; }
Have also confirmed that I have the running project and text document on the same folder. Somehow I keep getting an error indicating that it cannot open the input file.
The code I ran was: #include #include #include

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!