Cnvmendoza

Tickets Problem

Oct 20th, 2021 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     char ticketPrice1[80], numberOfTicketsSold1[80];
  13.     float totalTicketsSold = 0, totalSaleAmount = 0;
  14.     ifstream file;
  15.     file.open("ticketPrice.txt");
  16.     ifstream file1;
  17.     file1.open("numberofTicketsSold.txt");
  18.     if(!file.is_open() && !file1.is_open()){
  19.         cout << "File does not exist." << endl;
  20.        
  21.     }
  22.     else {
  23.         /*string ticketPrice;
  24.         while(file.good())
  25.         {
  26.             getline(file,ticketPrice);
  27.             cout << ticketPrice << endl;
  28.         }*/
  29.         while (file.eof()==0 && file1.eof()==0)
  30.         {
  31.             // File
  32.             file.getline(ticketPrice1, sizeof(ticketPrice1));
  33.             file1.getline(numberOfTicketsSold1, sizeof(numberOfTicketsSold1));
  34.            
  35.             // Test
  36.             // cout << ticketPrice1 << "\t" << numberOfTicketsSold1 << endl;
  37.             // Char to Float
  38.             float ticketPrice = atof(ticketPrice1);
  39.             float numberOfTicketsSold = atof(numberOfTicketsSold1);
  40.             // Total
  41.    
  42.             // cout << setprecision(2) << fixed << showpoint << ticketPrice * numberOfTicketsSold << endl;
  43.             float sales;
  44.             sales = ticketPrice * numberOfTicketsSold;
  45.            
  46.             char sales1[80] = (char)sales;
  47.             ofstream file3;
  48.             file3.open("sales1.txt");
  49.            
  50.             file3 << sales1 << endl;
  51.            
  52.             ifstream file4;
  53.             file4.open("sales1.txt")
  54.            
  55.             float totalTicketsSold;
  56.             totalTicketsSold = atof(sales1)
  57.            
  58.            
  59.            
  60.             //cout << setprecision(2) << fixed << showpoint << sales << endl;
  61.            
  62.  
  63.            
  64.             //totalTicketsSold = 0;
  65.             //cout << "Total Number of Tickets Sold: " << totalTicketsSold << endl;
  66.             //cout << "Total Sale Amount: " << totalSaleAmount << endl;
  67.             ;
  68.         }
  69.  
  70.  
  71.     }
  72.         return 0;
  73. }
  74.  
  75.  
Add Comment
Please, Sign In to add comment