I dont know what I'm doing wrong
Dec 17, 2018 at 8:39am UTC
Hello all, so i have done this program to be used by the (police) to add tickets (this is not real for the police) but every time i run it it just keeps repeating the choices and i don't know whats the problem because the program is running
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
//include "pch.h"
#include <iostream>
#include<fstream>
#include<string>
using namespace std;
//--------------------------------------------------------------
int plateNo[9999];
int ticketNo[9999];
string date[9999];
int fine[9999];
string status[9999];
int counter = 0;
//--------------------------------------------------------------
void readData()
{
fstream tvd;
tvd.open("trafficviolationdatabase.txt" ); //to read the traffic violation database
if (tvd)
while (!tvd.eof())
{
tvd >> plateNo[counter] >> ticketNo[counter] >> date[counter] >> fine[counter] >> status[counter];
counter++;
}
tvd.close();
if (!tvd) //to check if file opened successfully
cout << "Can't open input file!\n" ;
}
//--------------------------------------------------------------
int displayMenu()
{
cout << "1. Add new ticket\n2. Display all violation tickets\n3. Search for tickets by car plate no.\n4. Display all tickets that are not paid yet\n5. Display tickets for a specific date\n6. Exit\nChoice:\n" ;
int choice;
cin >> choice;
return choice;
}
//--------------------------------------------------------------
void addNewTicket()
{
ofstream output;
output.open("trafficviolationdatabase.txt" , ios::app);
for (int i = 0; i < counter; i++)
{
if (output.eof())
{
output << plateNo[i] << ticketNo[i] << date[i] << fine[i] << status[i];
break ;
}
}
}
//--------------------------------------------------------------
void showAllTickets()
{
cout << "Violation\t" << "Plate Number\t" << "Ticket Number\t" << "Date\t\t" << "Fine\t" << "Status" << endl;
for (int i = 0; i < counter; i++)
{
cout << "Violation " << i+1 << ":\t" << plateNo[i] << "\t\t" << ticketNo[i] << "\t\t" << date[i] << "\t" << fine[i] << "\t" << status[i] << endl;
}
}
//--------------------------------------------------------------
void showUnpaidTickets()
{
int i;
for (i = 0; i < counter; i++)
{
if (status[i] == "unpaid" )
{
cout << plateNo[i] << "\t" << ticketNo[i] << "\t" << date[i] << "\t" << fine[i] << "\t" << status[i] << endl;
break ;
}
}
if (i == counter)
cout << "No unpaid tickets found.\n" ;
}
//--------------------------------------------------------------
void searchByPlateNo()
{
int plateno, i;
cout << "Enter Plate Number: \n" ;
cin >> plateno;
for (i = 0; i < counter; i++)
{
if (plateNo[i] == plateno)
{
cout << plateNo[i] << "\t" << ticketNo[i] << "\t" << date[i] << "\t" << fine[i] << "\t" << status[i] << endl;
break ;
}
}
if (i == counter)
cout << "No entry was found for this plate number.\n" ;
}
//--------------------------------------------------------------
void searchByDate()
{
int i;
string udate;
cout << "Enter Desired Date: \n" ;
cin >> udate;
for (i = 0; i < counter; i++)
{
if (date[i] == udate)
{
cout << plateNo[i] << "\t" << ticketNo[i] << "\t" << date[i] << "\t" << fine[i] << "\t" << status[i] << endl;
break ;
}
}
if (i == counter)
cout << "No entry was found for this date.\n" ;
}
//--------------------------------------------------------------
int main()
{
readData();
int selection = displayMenu();
while (selection != 6)
{
switch (selection)
{
case 1: addNewTicket();
break ;
case 2: showAllTickets();
break ;
case 3: searchByPlateNo();
break ;
case 4: showUnpaidTickets();
break ;
case 5: searchByDate();
break ;
}
selection = displayMenu();
}
return 0;
system("pause" );
}
Last edited on Dec 17, 2018 at 8:51am UTC
Dec 17, 2018 at 8:44am UTC
Please edit your post to include [co de][/code] tags around the code (use the <> format icon).
Dec 17, 2018 at 8:51am UTC
like this?
Dec 17, 2018 at 9:49am UTC
addNewTicket() doesn't actually add any new tickets. It just writes the current tickets to file.
Topic archived. No new replies allowed.