Cnvmendoza

Tickets

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