Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main #3

Closed
Tracked by #10
alikzalikz opened this issue Jan 24, 2023 · 0 comments
Closed
Tracked by #10

main #3

alikzalikz opened this issue Jan 24, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@alikzalikz
Copy link
Owner

main function

RailwayCli/main.cpp

Lines 283 to 345 in 021ebb1

int main()
{
cout << "---- RAILWAY Cli ----\n\n";
bool state = true;
string num;
while(state)
{
cout << "1. Reserve a Seat" << endl;
cout << "2. Reserve a Compartment" << endl;
cout << "3. Check Ticket" << endl;
cout << "4. Ticket Refund" << endl;
cout << "5. Exit" << endl;
cout << "Please Choose Number: ";
cin >> num;
switch(HashIt(num))
{
case e1:
{
AddSeat();
break;
}
case e2:
{
AddCompartment();
break;
}
case e3:
{
string fullName = GiveFullName();
if (HaveTicket(fullName))
{
cout << "\n-- Passenger Have Ticket Already! --" << endl;
ShowTicket(fullName);
}
else
{
cout << "\nSorry, Passenger don't have Ticket\n\n\n";
}
break;
}
case e4:
{
string fullName = GiveFullName();
RefundTicket(fullName);
break;
}
case e5:
{
cout << "\n-- GOOD LUCK --";
state = false;
break;
}
case other:
{
cout << "\n-- Invalid Number! Please Try again --\n\n\n";
break;
}
}
}
return 0;
}

in switch case statement, don't worry about e1, e2 ,e3, ... and so on.
when we use normally 1, 2, 3, ...
and client is type like 53 get stuck at a infinite loop and crash
even though we use default: key word on last case,
so, we need two use something different for this issue
use enum!
and translate elements to numbers like this:

RailwayCli/main.cpp

Lines 263 to 281 in 021ebb1

enum string_code
{
e1,
e2,
e3,
e4,
e5,
other
};
string_code HashIt (string const& inString)
{
if (inString == "1") return e1;
if (inString == "2") return e2;
if (inString == "3") return e3;
if (inString == "4") return e4;
if (inString == "5") return e5;
else return other;
}

This was referenced Jan 24, 2023
@alikzalikz alikzalikz added the documentation Improvements or additions to documentation label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant