hi guys im new to c++ can i have some assist ?

The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets box, sideline, premium, and general admission. After each game, data is stored in a file in the following form:
ticketPrice numberOfTicketsSold
250 5750
100 28000
50 35750
25 18750

output the number of tickets sold and the total sale amount. Format your output with two decimal places.

my current file for SampleData.txt
250 5750
100 28000
50 35750
25 18750

my file for ReformatData.dat
Number of tickets sold = 0
Sale amount = $0

Now i couldnt get the numbers of tickets sold and sale amount. may i have some assist on where should i change ? thanks in advanced!

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()

 double tPrice;
 int numOfTicketsSold=0;
 int ticketsSold;
 double totalSale=0;

 ifstream inFile;
 ofstream outFile;


outFile << fixed << showpoint << setprecision(2);
 cout << "wait " << endl;
 for (int i=0; i<4; i++)
     inFile >> tPrice >> ticketsSold;



 outFile << "Number of tickets sold = "  << numOfTicketsSold << endl;

 outFile << "Sale amount = $" << totalSale << endl;


 return 0;
6 Months
Discussion Span
Last Post by rproffitt

Simple two-dimensional matrix. First column is the ticket price. Second is the number of tickets were sold at that price. To compute the income, iterate through the matrix, row by row, multiplying the price by number of tickets. Got it? If not, go back to your basic maths.


No need for an array, just read each line from the file, calculate the price x num tickets, add that to a total that you initialise before starting to read the file,


I don't know if you guys noticed i post my code up there is to see where my mistake went. and this isn't about using array. the reason why im posting this is because the calculation of it does not went into my "FormatData.dat" file. therefore correcting where my mistakes are in the code is more useful than criticizing me.


One of your problems is here:


You're overwriting totalSale instead of adding to it:

 totalSale += tPrice * ticketsSold;

Edited by tinstaafl

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.