Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <stdlib.h>
- using namespace std;
- int main(){
- // Variables
- char ticketPrice[80], numberOfTicketsSold[80];
- // Opening sales1.txt
- fstream file;
- file.open("sales1.txt");
- /* Inputs for:
- ticketPrice numberOfTicketsSold
- 250.75 5750
- 100.50 28000
- 50.25 35750
- 25.00 18750
- */
- // atof converts char to float
- // first_set to fourth_set contains numberOfTicketsSold for totalNumberOfTicketsSold
- // first_data to fourth_data contains the values of the product of ticketPrice and numberOfTicketsSold for totalSaleAmount
- // cout with tabs shows sample set
- file >> ticketPrice >> numberOfTicketsSold;
- //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
- float first_set = atof(numberOfTicketsSold);
- float first_data = atof(ticketPrice) * atof(numberOfTicketsSold);
- file >> ticketPrice >> numberOfTicketsSold;
- //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
- float second_set = atof(numberOfTicketsSold);
- float second_data = atof(ticketPrice) * atof(numberOfTicketsSold);
- file >> ticketPrice >> numberOfTicketsSold;
- //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
- float third_set = atof(numberOfTicketsSold);
- float third_data = atof(ticketPrice) * atof(numberOfTicketsSold);
- file >> ticketPrice >> numberOfTicketsSold;
- //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
- float fourth_set = atof(numberOfTicketsSold);
- float fourth_data = atof(ticketPrice) * atof(numberOfTicketsSold);
- // Total Number of Tickets Sold
- float totalNumberOfTicketsSold = first_set + second_set + third_set + fourth_set;
- // Total Sale Amount
- float totalSaleAmount = first_data + second_data + third_data + fourth_data;
- cout << setprecision(2) << fixed << showpoint;
- cout << "Total Number Of Tickets Sold: " << totalNumberOfTicketsSold << endl;
- cout << "Total Sale Amount: " << totalSaleAmount << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement