Advertisement
Cnvmendoza

fstream

Nov 6th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. int main(){
  8.     // Variables
  9.     char ticketPrice[80], numberOfTicketsSold[80];
  10.     // Opening sales1.txt
  11.     fstream file;
  12.     file.open("sales1.txt");
  13.     /* Inputs for:
  14.     ticketPrice numberOfTicketsSold
  15.    
  16.     250.75 5750
  17.     100.50 28000
  18.     50.25 35750
  19.     25.00 18750
  20.    
  21.     */
  22.     // atof converts char to float
  23.     // first_set to fourth_set contains numberOfTicketsSold for totalNumberOfTicketsSold
  24.     // first_data to fourth_data contains the values of the product of ticketPrice and numberOfTicketsSold for totalSaleAmount
  25.     // cout with tabs shows sample set
  26.     file >> ticketPrice >> numberOfTicketsSold;
  27.     //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
  28.     float first_set = atof(numberOfTicketsSold);
  29.     float first_data = atof(ticketPrice) * atof(numberOfTicketsSold);
  30.     file >> ticketPrice >> numberOfTicketsSold;
  31.     //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
  32.     float second_set = atof(numberOfTicketsSold);
  33.     float second_data = atof(ticketPrice) * atof(numberOfTicketsSold);
  34.     file >> ticketPrice >> numberOfTicketsSold;
  35.     //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
  36.     float third_set = atof(numberOfTicketsSold);
  37.     float third_data = atof(ticketPrice) * atof(numberOfTicketsSold);
  38.     file >> ticketPrice >> numberOfTicketsSold;
  39.     //cout << ticketPrice << "\t" << numberOfTicketsSold << endl;
  40.     float fourth_set = atof(numberOfTicketsSold);
  41.     float fourth_data = atof(ticketPrice) * atof(numberOfTicketsSold);
  42.    
  43.     // Total Number of Tickets Sold
  44.     float totalNumberOfTicketsSold = first_set + second_set + third_set + fourth_set;
  45.     // Total Sale Amount
  46.     float totalSaleAmount = first_data + second_data + third_data + fourth_data;
  47.     cout << setprecision(2) << fixed << showpoint;
  48.     cout << "Total Number Of Tickets Sold: " << totalNumberOfTicketsSold << endl;
  49.     cout << "Total Sale Amount: " << totalSaleAmount << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement