************* Please make sure it will run on visual studio. Thank you. ********
ID: 3839208 • Letter: #
Question
************* Please make sure it will run on visual studio. Thank you.********************
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, named ticketdata input.txt, in the following form: 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 in the output file named ticketdata output.txtExplanation / Answer
I hope you want this in C++.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream in("ticketdatainput.txt");
ofstream out("ticketdataoutput.txt");
char junk[50];
float cost = 0.0f;
int numOfTickets = 0;
double amount = 0.0;
if(!in){
cout<< "ticketdatainput.txt : File not found" <<endl;
return -1;
}
if(!out){
cout<< "ticketdataoutput: Unable to open file" <<endl;
return -1;
}
in >> junk >> junk;
while(in >> cost >> numOfTickets){
amount += cost * numOfTickets;
}
out<< "Total cost : " << fixed << amount ;
in.close();
out.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.