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
...

Sample data are shown below:

250 5750
100 28000
50 35750
25 18750

The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.

good luck!


Additional Details

/*
*/
// program to claculate total tickets sold and total gross ammount
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

int main()

{

//declare variables
ifstream inFile;


int ticketPrice;
int noOfTicketSold;

inFile.open("c:\\Dev-Cpp\\inFile.txt");

cout << fixed << showpoint;
cout << setprecision(2);

cout << "Processing data" << endl;


while( inFile >> ticketPrice >> noOfTicketSold);




{
cout << "Number of tickets sold : " << noOfTicketSold << endl;
cout << "Total sale ammount : " << ticketPrice * noOfTicketSold << endl;}

inFile.close();

return 0;

}

that is my code but it si not working i tried but failed miserably :-(


my result comes out as number of tickets sold : 2

total sale ammount :179022898

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
...

Sample data are shown below:

250 5750
100 28000
50 35750
25 18750

The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.

good luck!


Additional Details


/*
*/
// program to claculate total tickets sold and total gross ammount
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

int main()

{

//declare variables
ifstream inFile;


int ticketPrice;
int noOfTicketSold;

inFile.open("c:\\Dev-Cpp\\inFile.txt");

cout << fixed << showpoint;
cout << setprecision(2);

cout << "Processing data" << endl;


while( inFile >> ticketPrice >> noOfTicketSold);


{
cout << "Number of tickets sold : " << noOfTicketSold << endl;
cout << "Total sale ammount : " << ticketPrice * noOfTicketSold << endl;}

inFile.close();

return 0;

}

that is my code but it si not working i tried but failed miserably :-(


my result comes out as number of tickets sold : 2

total sale ammount :179022898

Please format your code and use code tags:

[code]

// paste code here

[/code]

At the very least, you have a problem here:

while( inFile >> ticketPrice >> noOfTicketSold)[COLOR="Red"];[/COLOR]

Delete the semicolon. Having the semicolon is the equivalent of your while loop looking like this:

while( inFile >> ticketPrice >> noOfTicketSold)
{
}

The cout statements are NOT inside your while loop when you have that semicolon in there. Delete it and see if you get better results.

i did that now my result comes out as processing data ..hehe i am a bignee its my second code that i am writing i am stuck big time

i did that now my result comes out as processing data ..hehe i am a bignee its my second code that i am writing i am stuck big time

Well, I got numbers to output when I took that semicolon out. I'd say your code has changed from what you've posted or your input file can't be found, likely the latter.

Try this program and see if the file opens:

// program to claculate total tickets sold and total gross ammount
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

int main()

{

//declare variables
ifstream inFile;


int ticketPrice;
int noOfTicketSold;

inFile.open("c:\\Dev-Cpp\\inFile.txt");
if (inFile.fail ())
{
     cout << "Couldn't open input file.  Press enter to exit." << endl;
     cin.get ();
     return 1;  // exit with error
}

cout << fixed << showpoint;
cout << setprecision(2);

cout << "Processing data" << endl;


while( inFile >> ticketPrice >> noOfTicketSold)




{
cout << "Number of tickets sold : " << noOfTicketSold << endl;
cout << "Total sale ammount : " << ticketPrice * noOfTicketSold << endl;}

inFile.close();
cin.get();
return 0;

}

well thanxx this did work but what was the problem really can u explain in eleboration i would highly appriciate it and also i need the sum total off all the ammounts how can i do that ?

well thanxx this did work but what was the problem really can u explain in eleboration i would highly appriciate it and also i need the sum total off all the ammounts how can i do that ?

Well, if it worked, then there IS no problem. Define "worked". Did the file open or not? All I did was remove the semicolon and post what you originally had posted, which looks OK aside from the semicolon. Note, I changed the path to be the same directory as the program is in. I can't recall off the top of my head whether Windows' directories have forward or backward slashes and whether you need to use an escape character. Did the file open or did the program abort?

Well, if it worked, then there IS no problem. Define "worked". Did the file open or not? All I did was remove the semicolon and post what you originally had posted, which looks OK aside from the semicolon. Note, I changed the path to be the same directory as the program is in. I can't recall off the top of my head whether Windows' directories have forward or backward slashes and whether you need to use an escape character. Did the file open or did the program abort?

the program gave the answers but not as expected it is giving the individual number of tickets sold and than the individual revenue from each type of tickets sold but i need to get is total number of tickets sold and also the total revenue ..now i dont know how to do that .. so i was working on a program that was not wrong just neede to put the correct path for the file name ..hehe

To do that, you can declare another 2 variable name total_ticket_sold and total_revenue. Then assign them with value 0. In the while loop, add another 2 lines of code:

total_ticket += noOfTicketSold;
total_revenue += (ticketPrice * noOfTicketSold);

Lastly, cout both outside the while loop.

This should work fine. :)

thanx for the help u were awesome and yeah now i have a little more knowledge and thanx for explaining me everything u were gr88

//by mCUBE, this is the right code, i'm sure In Shaa Allah.

import javax.swing.JOptionPane;
import java.io.*;
import java.util.Scanner;

public class totalTicket
{
    public static void main(String args[])
    {
        String inputStr;
        String outputStr;

        int noOfTicketsSold_Box, noOfTicketsSold_Sideline, noOfTicketsSold_Premium, noOfTicketsSold_General;
        double totalSaleAmount_Box, totalSaleAmount_Sideline, totalSaleAmount_Premium, totalSaleAmount_General;

        int totalTicketsSold;
        double totalSalesAmount;

        Scanner input = new Scanner("ticketSales.dat");

        inputStr = JOptionPane. showInputDialog
            ("ENTER THE TOTAL NUMBER OF TICKET(S) SOLD FOR BOX SEAT ADMISSION.");   
        noOfTicketsSold_Box= Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("ENTER THE TOTAL NUMBER OF TICKET(S) SOLD FOR SIDELINE SEAT ADMISSION.");  
        noOfTicketsSold_Sideline = Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("ENTER THE TOTAL NUMBER OF TICKET(S) SOLD FOR PREMIUM SEAT ADMISSION.") ;   
        noOfTicketsSold_Premium = Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("ENTER THE TOTAL NUMBER OF TICKET(S) SOLD FOR GENERAL SEAT ADMISSION.");      
        noOfTicketsSold_General = Integer.parseInt(inputStr);

        totalSaleAmount_Box = noOfTicketsSold_Box * 250;
        totalSaleAmount_Sideline = noOfTicketsSold_Sideline * 100;
        totalSaleAmount_Premium = noOfTicketsSold_Premium * 50;
        totalSaleAmount_General = noOfTicketsSold_General * 25;

        totalTicketsSold = noOfTicketsSold_Box + noOfTicketsSold_Sideline + noOfTicketsSold_Premium + noOfTicketsSold_General;
        totalSalesAmount = totalSaleAmount_Box + totalSaleAmount_Sideline + totalSaleAmount_Premium + totalSaleAmount_General;



        outputStr = "1. NUMBER OF BOX TICKETS SOLD: "
            + (noOfTicketsSold_Box) + "\n"
            + "-BOX TOTAL: $"
            + String.format("%.2f", totalSaleAmount_Box) + "\n"

            + "2. NUMBER OF SIDELINE TICKETS SOLD : "
            + (noOfTicketsSold_Sideline) + "\n"
            + "-SIDELINE TOTAL: $"
            + String.format("%.2f", totalSaleAmount_Sideline) + "\n"

            + "3. NUMBER OF PREMIUM TICKETS SOLD: "
            + (noOfTicketsSold_Premium) + "\n"
            + "-PREMIUM TOTAL: $"
            + String.format("%.2f", totalSaleAmount_Premium) + "\n"

            + "4. NUMBER OF GENERAL TICKETS SOLD: "
            + (noOfTicketsSold_General) + "\n"
            + "-GENERAL TOTAL: $"
            + String.format("%.2f", totalSaleAmount_General) + "\n\n"

            + "*THE TOTAL NUMBER OF SOLD TICKETS IS: "
            + (totalTicketsSold) + "\n"
            + "*THE TOTAL AMOUNT OF SALES IS: $"
            + String.format("%.2f", totalSalesAmount) + "\n";

        JOptionPane.showMessageDialog(null, outputStr,
            "FOOTBALL STADIUM SALES TICKETS.",
            JOptionPane.INFORMATION_MESSAGE);

        System.exit(0);
    }
}

Um? You resurected a 4 year old thread about C++ to post Java code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.