my code is giving an infinte loop when i enter the flight iD. kindly fix it the text file of flights.txt is f1: (Islamabad, Amman) Tue, Thu @2:00 f2: (Islamabad, Amman) Wed @18:00 f3: (Islamabad, Paris) Mon, Sat @13:30 f4: (Islamabad, Madrid) Mon @9:00 f5: (Islamabad, Dubai) Mon, Tue, Thu, Sun @19:15 f6: (Islamabad, Cairo) Tue, Thu @14:00
I see you have a C++ Airline Reservation System with an infinite loop issue when entering flight IDs. Let me analyze and fix this problem.
Looking at your code, I can see that the issue is likely in the flight parsing logic. Let me fix this for you:
The infinite loop was occurring due to two main issues:
cin
stream to enter a failed state, leading to an infinite loop.<limits>
header needed for numeric_limits
These changes will prevent the infinite loop by properly validating input and ensuring the program can recover from invalid data entry.
Would you like me to explain any other parts of the code or make additional improvements to the system?
I've identified the issue in your code that's causing the infinite loop when entering a flight ID. The problem is in the parseFlightData
function which is not correctly parsing the flight information from the flights.txt file.
Let me fix this for you:
fixed-airport-system.cpp
I've fixed the issue that was causing the infinite loop when entering a flight ID. The problem was in the parseFlightData
function which wasn't correctly parsing the flight information from the flights.txt file.
The main issues I fixed were:
parseFlightData
function to correctly extract flight numbers, source, destination, days, and time from the text file.loadFlightsFromFile
method to properly handle the flight data format and assign planes to flights.The code should now correctly parse the flight data from the flights.txt file and avoid the infinite loop when entering a flight ID during reservation.