From 914097cbcd4eef14c7825b142d3b125cc51e631e Mon Sep 17 00:00:00 2001 From: Jankatay <162386918+Jankatay@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:45:05 -0700 Subject: [PATCH] Update main.cpp Remove recursive call to main(). --- Project_Flies/src/main.cpp | 52 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/Project_Flies/src/main.cpp b/Project_Flies/src/main.cpp index 5ac76c1..8537c52 100644 --- a/Project_Flies/src/main.cpp +++ b/Project_Flies/src/main.cpp @@ -17,26 +17,35 @@ int num = 0; int main() { - int choice; - cout << "\n\n--------------------------------------------------------------------" << endl; - cout << " Training Schedule Management System " << endl; - cout << "--------------------------------------------------------------------" << endl; - cout << "\n\n\t\tWelcome To Home Page" << endl; - cout << "\n\t\tPress 1 --> Admin Login" << endl; - cout << "\t\tPress 2 --> Faculty Login" << endl; - cout << "\t\tPress 3 --> Exit" << endl; - cout << "\nPlease Enter Your Choice : "; - cin >> choice; - - if (cin.fail()) + bool repeat{ true }; + const string prompt { - cin.clear(); - cin.ignore(512, '\n'); - cout << "\nPlease enter a number!!" << endl; - main(); - } - else + "\n" + "\n--------------------------------------------------------------------" + "\n Training Schedule Management System " + "\n--------------------------------------------------------------------" + "\n\n\n\t\tWelcome To Home Page" + "\n\n\t\tPress 1 --> Admin Login" + "\n\t\tPress 2 --> Faculty Login" + "\n\t\tPress 3 --> Exit " + "\n\nPlease Enter Your Choice : " + }; + + while(repeat) { + int choice; + cout << prompt; + cin >> choice; + + while (cin.fail()) + { + cin.clear(); + cin.ignore(512, '\n'); + cout << "\nPlease enter a number!!" << endl; + cout << prompt; + cin >> choice; + } + switch (choice) { case 1: @@ -50,8 +59,11 @@ int main() break; default: cout << "\nPlease select from the options given above" << endl; - main(); + repeat = true; + continue; //Repeat loop. } + + repeat = false; } } @@ -145,4 +157,4 @@ void facultyLogin() //UTC-007 & AA-001 } main(); } -} \ No newline at end of file +}