#include <iostream>#include <iomanip>#include <fstream>using namespace std;int main(){ // Declare variables to hold ticket data int price, tickets, sales, x; int totalsales = 0; int totaltickets = 0; // Declare file stream variables ifstream fIn; ofstream fOut; // Open input/output files fIn.open("F:\\Homework Problems\\ticket-sales\\tickets.txt"); fOut.open("F:\\Homework Problems\\ticket-sales\\output.txt"); // Grab input from the file // 4 Lines, so, loop while x is less than 4 (0 through 3 is 4 lines) for (int x = 0; x < 4;) { // Increment counter so it knows when to stop looping x++; fIn >> price >> tickets; sales = price * tickets; // Calculate totals (tickets, sales) during each loop and hold that value // in these two variables totalsales += sales; totaltickets += tickets; // Testing purposes: // Ensure proper data being read from file on each line // fOut << "Line " << x << ": " << totalsales << ", " << totaltickets << endl; } // Set required output formatting cout << fixed << showpoint << setprecision(2) << endl; // Tell user where data is being written cout << "Writing data to file: 'output.txt'" << endl; // Testing purposes: // Ensure final line being read is the final line of the file // fOut << "Price: " << price << ", Tickets: " << tickets << ", Sales: " << sales << endl; // Write total tickets sold to file fOut << "Total Tickets Sold: " << totaltickets << endl; // Write total sales to file fOut << "Total Sales: $" << totalsales << endl; // Close input and output files fIn.close(); fOut.close(); return 0;}