0% found this document useful (0 votes)
11 views34 pages

Codemo2 Title

This document is a C++ program for a hotel reservation system that allows users to book hotel rooms, view bookings, change bookings, and cancel bookings. It includes structures for guest and hotel booking information, functions for managing bookings, and a main menu for user interaction. The program also validates user input for various fields such as name, age, gender, and contact number.

Uploaded by

tojizeninn12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views34 pages

Codemo2 Title

This document is a C++ program for a hotel reservation system that allows users to book hotel rooms, view bookings, change bookings, and cancel bookings. It includes structures for guest and hotel booking information, functions for managing bookings, and a main menu for user interaction. The program also validates user input for various fields such as name, age, gender, and contact number.

Uploaded by

tojizeninn12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <iostream>

#include <string>

#include <fstream>

#include <vector>

#include <stack>

#include <list>

#include <algorithm>

#include <sstream>

#include <cctype>

#include <limits>

#include <iomanip>

using namespace std;

#define RESET "\033[0m"

#define RED "\033[31m"

#define GREEN "\033[32m"

#define YELLOW "\033[33m"

#define CYAN "\033[36m"

#define BOLD "\033[1m"

struct Guest {

string name;

int age;

string gender;

string contactNumber;

};

struct HotelBooking {
Guest guest;

string hotelLocation;

string roomType;

string roomNumber;

string checkInDate;

string checkOutDate;

double totalPrice; // Add this line for the total price

bool operator==(const HotelBooking &other) const {

return [Link] == [Link] &&

[Link] == [Link] &&

[Link] == [Link] &&

[Link] == [Link] &&

hotelLocation == [Link] &&

roomType == [Link] &&

roomNumber == [Link] &&

checkInDate == [Link] &&

checkOutDate == [Link];

};

stack<HotelBooking> bookingHistory;

list<HotelBooking> bookingsList;

const int ROOMS = 40;

string availableRooms[ROOMS] = {

"R101", "R102", "R103", "R104", "R105",

"R106", "R107", "R108", "R109", "R110",


"R111", "R112", "R113", "R114","R115",

"R116", "R117", "R118", "R119", "R120",

"R121", "R122", "R123", "R124", "R125",

"R126", "R127", "R128", "R129", "R130",

"R131", "R132", "R133", "R134","R135",

"R136", "R137", "R138", "R139", "R140"

};

string roomTypes[3] = {"Single", "Double", "Suite"};

const double basePrices[3] =

{3000.00, 5000.00, 7000.00};

struct Payment {

double gcashBalance = 20000.00; // Updated balance for GCash

double paymayaBalance = 20000.00; // Updated balance for PayMaya

double paypalBalance = 20000.00; // Updated balance for PayPal

};

void showMainMenu();

void bookHotel();

void viewBookings();

void changeBooking();

void cancelBooking();

void assignRoomSchedule(HotelBooking& booking);

double calculatePrice(const string &roomType, int hotelIndex);

bool isValidContactNumber(const string &contactNumber);

bool isValidName(const string& name);

void loadBookingsFromFile();
void processPayment(double totalPrice);

bool isValidDate(const string& date);

int calculateDaysBetween(const string& startDate, const string& endDate);

int main() {

loadBookingsFromFile();

showMainMenu();

return 0;

void showMainMenu() {

int choice;

do {

system("cls");

cout << BOLD << CYAN;

cout << "|================ Hotel Reservation System =================|" << RESET << endl;

cout << "| 1. Book a Hotel Room |" << endl;

cout << "| 2. View My Bookings |" << endl;

cout << "| 3. Change My Booking |" << endl;

cout << "| 4. Cancel My Booking |" << endl;

cout << "| 5. Exit |" << endl;

cout << "|===========================================================|" << endl;

cout << "Please enter your choice (1-5): ";

cin >> choice;

[Link]();

[Link](numeric_limits<streamsize>::max(), '\n');

switch (choice) {
case 1:

bookHotel();

break;

case 2:

viewBookings();

break;

case 3:

changeBooking();

break;

case 4:

cancelBooking();

break;

case 5:

cout << "Exiting the system. Thank you!\n";

break;

default:

cout << RED << "Invalid choice. Please try again.\n" << RESET;

if (choice != 5) {

cout << YELLOW << "Press Enter to continue..." << RESET;

[Link]();

[Link]();

} while (choice != 5);

void bookHotel() {

system("cls");
HotelBooking booking;

cout << CYAN << "|================ Adding Hotel Reservation ================|" << RESET <<
endl;

while (true) {

cout << GREEN << "Enter your name (First Name Last Name): " << RESET;

[Link]();

getline(cin, [Link]);

if (isValidName([Link])) {

break;

} else {

cout << RED << "Invalid input. Please enter a valid name.\n" << RESET << endl;

cout << GREEN << "Enter your age: " << RESET;

while (true) {

cin >> [Link];

if ([Link]() || [Link] < 18) {

[Link]();

[Link](numeric_limits<streamsize>::max(), '\n');

cout << RED << "Please enter a valid age (18 or older): " << RESET;

} else {

[Link](numeric_limits<streamsize>::max(), '\n');

break;

}
}

cout << GREEN << "Enter your gender (Male 'M', Female 'F'): " << RESET;

while (true) {

cin >> [Link];

[Link](numeric_limits<streamsize>::max(), '\n');

if ([Link] == "M" || [Link] == "F" ||

[Link] == "m" || [Link] == "f") {

[Link] = toupper([Link][0]);

break;

} else {

cout << RED << "Please enter 'M' for Male or 'F' for Female: " << RESET;

cout << GREEN << "Enter your contact number (11 digits starting with '09'): " << RESET;

while (true) {

cin >> [Link];

if (isValidContactNumber([Link])) {

break;

} else {

cout << RED << "Must be exactly 11 digits and start with '09': " << RESET;

// Available room selection first

cout << GREEN << "Choose a room number from the available options:\n";

// Display available rooms only once


// Display available rooms with blanks for booked rooms

cout << GREEN << "Available Rooms: \n" << RESET;

for (int i = 0; i < ROOMS; i++) {

if (availableRooms[i] == "") { // If room is booked, show a blank

cout << "____" << "\t";

} else { // Show available room

cout << YELLOW << availableRooms[i] << "\t" << RESET;

if ((i + 1) % 5 == 0) { // Print 5 rooms per row

cout << endl;

while (true) {

cout << GREEN << "Enter room number: " << RESET;

cin >> [Link];

// Check if the input is a valid room number

bool roomAvailable = false;

for (int i = 0; i < ROOMS; i++) {

if (availableRooms[i] == [Link]) {

roomAvailable = true;

// Mark the room as booked by clearing the room in the available list

availableRooms[i] = "";

break;

}
}

// If room is available, break out of the loop

if (roomAvailable) {

break;

} else {

cout << RED << "Room number not available. Please choose another room number.\n" << RESET;

// Optionally, you can also check if the input was invalid (e.g., non-numeric input)

if ([Link]()) {

[Link](); // Clear the error flag

[Link](numeric_limits<streamsize>::max(), '\n'); // Ignore invalid input

cout << RED << "Invalid input. Please enter a valid room number.\n" << RESET;

// Room type selection (simplified to numbers)

cout<<"|"<<YELLOW<<"1. Single = 3000 "<<RESET<<"|"<<YELLOW<<"2. Double =


5000"<<RESET<<"|"<<YELLOW"3. Suite = 7000 "<<RESET<<"|"<<endl;

cout << GREEN << "\nChoose Room Type:"<<RESET;

int roomTypeChoice;

while (true) {

cin >> roomTypeChoice;

if (roomTypeChoice >= 1 && roomTypeChoice <= 3) {

[Link] = roomTypes[roomTypeChoice - 1];

break;

} else {

cout << RED << "Invalid choice. Please choose 1, 2, or 3: " << RESET;
}

assignRoomSchedule(booking);

double totalPrice = calculatePrice([Link], 0);

cout << GREEN << "Booking successful! Please proceed with payment.\n" << RESET << endl;

processPayment(totalPrice);

system("cls");

showMainMenu();

void assignRoomSchedule(HotelBooking& booking) {

// Input check-in date

while (true) {

cout << "\tEnter check-in date (DD/MM/YYYY): ";

cin >> [Link];

if (isValidDate([Link])) {

break;

} else {

cout << RED << "\tInvalid date! Ensure format is DD/MM/YYYY and within 2024.\n" << RESET;

}
// Input check-out date

while (true) {

cout << "\tEnter check-out date (DD/MM/YYYY): ";

cin >> [Link];

if (isValidDate([Link])) {

int stayDuration = calculateDaysBetween([Link], [Link]);

if (stayDuration > 0) {

[Link] = (stayDuration *500)+ calculatePrice ([Link], 0); // Calculate


price with room type

cout << GREEN << "\tStay duration: " << RESET<< stayDuration<<"days";

cout << YELLOW << "\nThe total price for your stay (" << [Link]

<< " room) is: " << RESET << fixed << setprecision(2) << [Link] << " PHP." << endl;

bookingsList.push_back(booking);

[Link](booking);

processPayment([Link]);

break;

} else {

cout << RED << "\tCheck-out date must be after check-in date.\n" << RESET;

} else {

cout << RED << "\tInvalid date! Ensure format is DD/MM/YYYY and within 2024.\n" << RESET;

}
}

double calculatePrice(const string &roomType, int hotelIndex) {

double price = 0.0;

if (roomType == "Single") {

price = basePrices[0]; // Room price for Single

} else if (roomType == "Double") {

price = basePrices[1]; // Room price for Double

} else if (roomType == "Suite") {

price = basePrices[2]; // Room price for Suite

return price;

bool bookingsLoaded = false;

void viewBookings() {

// Only load bookings from the file if they haven't been loaded already

if (!bookingsLoaded) {

loadBookingsFromFile();

system("cls");

if ([Link]()) {

cout << RED << "No bookings found.\n" << RESET << endl;

} else {
cout << CYAN << "=== Your Bookings ===\n" << RESET;

for (const auto& booking : bookingsList) {

cout << GREEN << "Guest: " << [Link] << RESET << endl;

cout << "Location: " << "Nueva Ecija" << endl;

cout << "Room Type: " << [Link] << endl;

cout << "Room Number: " << [Link] << endl;

cout << "Check-in Date: " << [Link] << endl;

cout << "Check-out Date: " << [Link] << endl;

cout << "Price: " << "PHP: "<<[Link] << endl;

cout << "-----------------------------\n";

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link]();

[Link]();

system("cls");

showMainMenu();

void changeBooking() {

system("cls");

if ([Link]()) {
cout << RED << "No bookings found to change.\n" << RESET << endl;

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link]();

[Link]();

system("cls");

showMainMenu();

return;

} else {

int index = 0;

cout << CYAN << "=== Your Bookings ===\n" << RESET;

for (const auto& booking : bookingsList) {

cout << GREEN << "INDEX: " << index++ << RESET << endl;

cout << "Guest: " << [Link] << endl;

cout << "Room Type: " << [Link] << endl;

cout << "Room Number: " << [Link] << endl;

cout << "Check-in Date: " << [Link] << endl;

cout << "Check-out Date: " << [Link] << endl;

cout << "-----------------------------\n";

int bookingIndex;

cout << "\tEnter the index of the booking you want to change: ";

cin >> bookingIndex;

if ([Link]() || bookingIndex < 0 || bookingIndex >= [Link]()) {

[Link]();

[Link](numeric_limits<streamsize>::max(), '\n');

cout << RED << "Invalid index. Returning to main menu.\n" << RESET << endl;

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;
[Link]();

[Link]();

system("cls");

showMainMenu();

return;

auto it = [Link]();

advance(it, bookingIndex);

HotelBooking& booking = *it;

// Menu to select what to change

int choice;

while (true) {

cout << CYAN << "=== What would you like to change? ===\n" << RESET;

cout << "1. Guest Information\n";

cout << "2. Room Type\n";

cout << "3. Room Number\n";

cout << "4. Check-in Date\nCheck-out Date\n";

cout << "Enter your choice (1-4): ";

cin >> choice;

// Validate menu choice

if ([Link]() || choice < 1 || choice > 4) {

[Link]();

[Link](numeric_limits<streamsize>::max(), '\n');

cout << RED << "Invalid input. Please select a valid option (1-4).\n" << RESET;

} else {

break;
}

// Perform changes based on the user's choice

switch (choice) {

case 1: { // Change Guest Information

char changeName;

cout << "\tCurrent Guest Name: " << [Link] << endl;

// Loop until the user provides valid input ('y' or 'n')

while (true) {

cout << "\tDo you want to change the guest name? (y/n): ";

cin >> changeName;

// Check if the input is valid

if (changeName == 'y' || changeName == 'Y' || changeName == 'n' || changeName == 'N') {

break; // Exit loop if input is valid

} else {

[Link](); // Clear any error state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear input buffer

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

if (changeName == 'y' || changeName == 'Y') {

while (true) {

cout << "Enter new name: ";

[Link](); // Clear any leftover newline characters

getline(cin, [Link]);
if (isValidName([Link])) {

break;

} else {

cout << RED << "Invalid input. Please enter a valid name." << RESET << endl;

break;

case 2: { // Change Room Type

char changeRoomType;

cout << "\tCurrent Room Type: " << [Link] << endl;

cout << "\tDo you want to change the room type? (y/n): ";

cin >> changeRoomType;

// Loop to handle invalid input for yes/no question

while (changeRoomType != 'y' && changeRoomType != 'Y' && changeRoomType != 'n' &&
changeRoomType != 'N') {

[Link](); // Clear any error state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear input buffer

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

cout << "\tDo you want to change the room type? (y/n): ";

cin >> changeRoomType;

if (changeRoomType == 'y' || changeRoomType == 'Y') {

cout << "| " << YELLOW << "1. Single = 3000 " << RESET

<< "| " << YELLOW << "2. Double = 5000 " << RESET
<< "| " << YELLOW << "3. Suite = 7000 " << RESET << " |" << endl;

cout << GREEN << "\nChoose Room Type: " << RESET;

int roomTypeChoice;

while (true) {

cin >> roomTypeChoice;

if ([Link]() || roomTypeChoice < 1 || roomTypeChoice > 3) {

[Link](); // Clear the error flag

[Link](numeric_limits<streamsize>::max(), '\n'); // Ignore invalid input

cout << RED << "Invalid choice. Please choose 1, 2, or 3: " << RESET;

} else {

// Update the room type and recalculate the price based on the new room type

double newRoomPrice = basePrices[roomTypeChoice - 1];

// Recalculate the total price with the new room type and new dates

int stayDuration = calculateDaysBetween([Link], [Link]);

[Link] = (stayDuration * 500) + (stayDuration * newRoomPrice);

// Update the room type

[Link] = roomTypes[roomTypeChoice - 1];

cout << GREEN << "\tRoom Type updated to: " << [Link] << RESET << endl;

cout << YELLOW << "\tNew Total Price: " << RESET << [Link] << " PHP" << endl;

break; // Exit loop when a valid input is entered

break;
}

case 3: { // Change Room Number

char changeRoom;

cout << "\tCurrent Room Number: " << [Link] << endl;

cout << "\tDo you want to change the room number? (y/n): ";

cin >> changeRoom;

// Loop to handle invalid input for yes/no question

while (changeRoom != 'y' && changeRoom != 'Y' && changeRoom != 'n' && changeRoom != 'N') {

[Link](); // Clear any error state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear input buffer

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

cout << "\tDo you want to change the room number? (y/n): ";

cin >> changeRoom;

if (changeRoom == 'y' || changeRoom == 'Y') {

cout << GREEN << "Available Rooms: \n" << RESET;

for (int i = 0; i < ROOMS; i++) {

if (availableRooms[i] == "") { // Booked rooms appear as blanks

cout << "____" << "\t";

} else {

cout << YELLOW << availableRooms[i] << "\t" << RESET;

if ((i + 1) % 5 == 0) { // Print 5 rooms per row

cout << endl;

}
cout << RESET << endl;

while (true) {

cout << GREEN << "Enter new room number: " << RESET;

string newRoomNumber;

cin >> newRoomNumber;

// Check if the new room number is available

bool roomAvailable = false;

for (int i = 0; i < ROOMS; i++) {

if (availableRooms[i] == newRoomNumber) {

roomAvailable = true;

// Mark the new room as booked

availableRooms[i] = "";

// Restore the old room to its original position

for (int j = 0; j < ROOMS; j++) {

if ("R" + to_string(j + 101) == [Link]) {

availableRooms[j] = [Link]; // Make old room available

break;

// Update the booking with the new room number

[Link] = newRoomNumber;

cout << GREEN << "\tRoom number updated successfully to " << newRoomNumber << "!\n" <<
RESET;

break;
}

if (roomAvailable) {

break; // Exit the loop if the room change was successful

} else {

cout << RED << "Room number not available. Please choose another room number.\n" << RESET;

break;

case 4: { // Change Check-in Date

char changeDates;

cout << "\tCurrent Check-in Date: " << [Link] << endl;

cout << "\tCurrent Check-out Date: " << [Link] << endl;

cout << "\tDo you want to change the check-in and check-out dates? (y/n): ";

cin >> changeDates;

// Loop to handle invalid input for yes/no question

while (changeDates != 'y' && changeDates != 'Y' && changeDates != 'n' && changeDates != 'N') {

[Link](); // Clear any error state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear input buffer

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

cout << "\tDo you want to change the check-in and check-out dates? (y/n): ";

cin >> changeDates;

}
if (changeDates == 'y' || changeDates == 'Y') {

while (true) {

cout << "\tEnter new check-in date (DD/MM/YYYY): ";

cin >> [Link];

if (isValidDate([Link])) {

break;

} else {

cout << RED << "\tInvalid date! Ensure format is DD/MM/YYYY and within 2024.\n" << RESET;

while (true) {

cout << "\tEnter new check-out date (DD/MM/YYYY): ";

cin >> [Link];

if (isValidDate([Link])) {

int stayDuration = calculateDaysBetween([Link], [Link]);

if (stayDuration > 0) {

[Link] = (stayDuration * 500) + calculatePrice([Link], 0);

cout << GREEN << "\tStay duration updated to: " << RESET << stayDuration << " days.\n";

cout << YELLOW << "\nThe new total price for your stay (" << [Link]

<< " room) is: " << RESET << fixed << setprecision(2) << [Link] << " PHP.\n";

break;

} else {

cout << RED << "\tCheck-out date must be after check-in date.\n" << RESET;

} else {

cout << RED << "\tInvalid date! Ensure format is DD/MM/YYYY and within 2024.\n" << RESET;

}
}

break;

default:

break;

cout << GREEN << "\nBooking updated successfully!\n" << RESET;

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link]();

[Link]();

system("cls");

showMainMenu();

void cancelBooking() {

system("cls");

if ([Link]()) {

cout << RED << "No bookings found to cancel.\n" << RESET << endl;

} else {

int index = 0;

cout << CYAN << "=== Your Bookings ===\n" << RESET;

for (const auto& booking : bookingsList) {

cout << GREEN << "INDEX: " << index++ << RESET << endl;

cout << "Guest: " << [Link] << endl;


cout << "Room Type: " << [Link] << endl;

cout << "Room Number: " << [Link] << endl;

cout << "Check-in Date: " << [Link] << endl;

cout << "Check-out Date: " << [Link] << endl;

cout << "Price: " << "PHP: "<<[Link] << endl;

cout << "-----------------------------\n";

int bookingIndex;

cout << "\tEnter the index of the booking you want to cancel: ";

cin >> bookingIndex;

if ([Link]() || bookingIndex < 0 || bookingIndex >= [Link]()) {

[Link]();

[Link](numeric_limits<streamsize>::max(), '\n');

cout << RED << "Invalid index. Returning to main menu.\n" << RESET << endl;

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link]();

[Link]();

system("cls");

showMainMenu();

return;

auto it = [Link]();

advance(it, bookingIndex);

char confirm;

cout << "\tAre you sure you want to cancel the booking for " << it->[Link]<< "? (y/n): ";
cin >> confirm;

if (confirm == 'y' || confirm == 'Y') {

[Link](it);

cout << GREEN << "\tBooking cancelled successfully!\n" << RESET << endl;

} else {

cout << YELLOW << "\tCancellation aborted. Returning to main menu.\n" << RESET << endl;

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link]();

[Link]();

system("cls");

showMainMenu();

void loadBookingsFromFile() {

ifstream file("[Link]");

if (file.is_open()) {

HotelBooking booking;

while (file >> [Link] >> [Link] >> [Link]

>> [Link] >> [Link] >> [Link]

>> [Link] >> [Link] >>


[Link]>>[Link]) {

// Add the booking to the list and history

bookingsList.push_back(booking);

[Link](booking);
// Mark the room as unavailable by removing it from availableRooms

for (int i = 0; i < ROOMS; i++) {

if (availableRooms[i] == [Link]) {

availableRooms[i] = ""; // Mark the room as unavailable

break;

[Link]();

bookingsLoaded = true; // Set the flag to true after loading the bookings

} else {

cout << RED << "Error loading bookings from file.\n" << RESET << endl;

void processPayment(double totalPrice) {

Payment paymentMethods; // Initialize payment methods

int paymentOption;

// Display the payment options menu once at the beginning

cout << "|================ Payment Options ========================|" << endl;

cout << "| 1. GCash |" << endl;

cout << "| 2. PayMaya |" << endl;

cout << "| 3. PayPal |" << endl;

cout << "| 4. Pay at the Counter |" << endl;

cout << "|==========================================================|" << endl;

cout << "Total Amount Due: " << fixed << setprecision(2) << totalPrice << " PHP\n";
while (true) { // Loop until valid payment is made or confirmed

cout << "Please select your payment method (1-4): ";

cin >> paymentOption;

// Validate input

if ([Link]() || paymentOption < 1 || paymentOption > 4) {

[Link](); // Clear invalid state

[Link](numeric_limits<streamsize>::max(), '\n'); // Ignore invalid input

cout << RED << "Invalid choice. Please enter a valid option (1-4).\n" << RESET;

continue; // Re-prompt the user

char confirm;

switch (paymentOption) {

case 1: // GCash Payment

cout << "You selected GCash.\n";

cout << "Current GCash balance: " << fixed << setprecision(2) <<
[Link] << " PHP\n";

do {

cout << "Are you sure you want to proceed with the payment of "

<< fixed << setprecision(2) << totalPrice << " PHP? (y/n): ";

cin >> confirm;

if ([Link]() || (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N')) {

[Link](); // Clear invalid state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear invalid input

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

} while (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N');
if (confirm == 'y' || confirm == 'Y') {

if ([Link] >= totalPrice) {

[Link] -= totalPrice;

cout << GREEN << "Payment successful! Remaining GCash balance: "

<< fixed << setprecision(2) << [Link] << " PHP.\n" << RESET;

break;

} else {

cout << RED << "You don't have enough balance in your GCash account.\n" << RESET;

} else {

cout << RED << "Payment not confirmed. Please select another option.\n" << RESET;

continue;

break;

case 2: // PayMaya Payment

cout << "You selected PayMaya.\n";

cout << "Current PayMaya balance: " << fixed << setprecision(2) <<
[Link] << " PHP\n";

do {

cout << "Are you sure you want to proceed with the payment of "

<< fixed << setprecision(2) << totalPrice << " PHP? (y/n): ";

cin >> confirm;

if ([Link]() || (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N')) {

[Link](); // Clear invalid state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear invalid input

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

} while (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N');
if (confirm == 'y' || confirm == 'Y') {

if ([Link] >= totalPrice) {

[Link] -= totalPrice;

cout << GREEN << "Payment successful! Remaining PayMaya balance: "

<< fixed << setprecision(2) << [Link] << " PHP.\n" << RESET;

break;

} else {

cout << RED << "You don't have enough balance in your PayMaya account.\n" << RESET;

} else {

cout << RED << "Payment not confirmed. Please select another option.\n" << RESET;

continue;

break;

case 3: // PayPal Payment

cout << "You selected PayPal.\n";

cout << "Current PayPal balance: " << fixed << setprecision(2) <<
[Link] << " PHP\n";

do {

cout << "Are you sure you want to proceed with the payment of "

<< fixed << setprecision(2) << totalPrice << " PHP? (y/n): ";

cin >> confirm;

if ([Link]() || (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N')) {

[Link](); // Clear invalid state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear invalid input

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

}
} while (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N');

if (confirm == 'y' || confirm == 'Y') {

if ([Link] >= totalPrice) {

[Link] -= totalPrice;

cout << GREEN << "Payment successful! Remaining PayPal balance: "

<< fixed << setprecision(2) << [Link] << " PHP.\n" << RESET;

break;

} else {

cout << RED << "You don't have enough balance in your PayPal account.\n" << RESET;

} else {

cout << RED << "Payment not confirmed. Please select another option.\n" << RESET;

continue;

break;

case 4: // Pay at the Counter

cout << "You selected Pay at the Counter. Proceeding with payment...\n";

do {

cout << "Are you sure you want to proceed with Pay at the Counter? (y/n): ";

cin >> confirm;

if ([Link]() || (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N')) {

[Link](); // Clear invalid state

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear invalid input

cout << RED << "Invalid choice. Please enter 'y' or 'n'.\n" << RESET;

} while (confirm != 'y' && confirm != 'Y' && confirm != 'n' && confirm != 'N');
if (confirm == 'y' || confirm == 'Y') {

cout << GREEN << "Payment successful! No balance change for this option.\n" << RESET;

break;

} else {

cout << RED << "Payment not confirmed. Please select another option.\n" << RESET;

continue;

break;

// If payment was successful, exit the loop and return to the main menu

cout << YELLOW << "\nPress Enter to return to the main menu..." << RESET;

[Link](numeric_limits<streamsize>::max(), '\n'); // Clear input buffer

[Link]();

showMainMenu(); // Return to the main menu

return; // Exit the function

bool isValidDate(const string& date) {

if ([Link]() != 10 || date[2] != '/' || date[5] != '/') {

return false;

int day = stoi([Link](0, 2));

int month = stoi([Link](3, 2));


int year = stoi([Link](6, 4));

if (year != 2024 || month < 1 || month > 12 || day < 1 || day > 31) {

return false;

// Check for days exceeding valid ranges in specific months

if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) {

return false;

if (month == 2 && day > 29) {

return false; // Assuming 2024 is a leap year

return true;

};

// Function to calculate the number of days between two dates

int calculateDaysBetween(const string& startDate, const string& endDate) {

int startDay = stoi([Link](0, 2));

int startMonth = stoi([Link](3, 2));

int startYear = stoi([Link](6, 4));

int endDay = stoi([Link](0, 2));

int endMonth = stoi([Link](3, 2));

int endYear = stoi([Link](6, 4));

// Convert dates to "days since start of year"

int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (startYear == 2024) daysInMonth[1] = 29; // Adjust February for leap year


int startTotalDays = startDay;

for (int i = 0; i < startMonth - 1; i++) {

startTotalDays += daysInMonth[i];

int endTotalDays = endDay;

for (int i = 0; i < endMonth - 1; i++) {

endTotalDays += daysInMonth[i];

return endTotalDays - startTotalDays;

};

bool isValidContactNumber(const string &contactNumber) {

if ([Link]() != 11) return false;

if ([Link](0, 2) != "09") return false;

for (char c : contactNumber) {

if (!isdigit(c)) return false;

return true;

bool isValidName(const string& name) {

if ([Link]()) return false;

bool hasValidCharacter = false;

size_t spaceCount = 0;
bool firstNameValid = false;

if (name[0] == ' ') return false;

for (size_t i = 0; i < [Link](); ++i) {

char ch = name[i];

if (isalpha(ch) || ch == '-') {

hasValidCharacter = true;

spaceCount = 0;

if (spaceCount == 0 && !firstNameValid) {

firstNameValid = true;

else if (ch == ' ') {

spaceCount++;

if (spaceCount > 1) {

return false;

} else {

return false;

return hasValidCharacter;

You might also like