🔒 Closed Atm coding (If and Switch Statement)

Status
Not open for further replies.
Yung switch pwedeng pamalit sa if-else lalo na kung masyado mahaba/madami yung conditions. Pero pag pinag-karambola mo, mas mahirap unawain. Suggest ko, stick with either switch o if-else.

Pag naayos mo na at na-implement yung suggestion sa taas, pwede mo din i-sama ang while loop (until the user enters the correct option, o he wants to quit altogether)

Code:
// The option to quit is not included. You can add it later.
while (pin != 123) {
    std::cout << "Incorrect PIN. Please re-enter: " << std::flush;
   std::cin >> pin;
}
// Condition above was satisfied. Now proceed here.
while (trans != 1 || trans || != 2 ...etc) {
        std::cout << "                   Menu                              " << "\n";
        std::cout << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _" << "\n";
        std::cout << "[1] Balance Inquiry" << "\n";
        std::cout << "[2] Withdrawal" << "\n";
        std::cout << "[3] Quit" << "\n";
        std::cout << "Select Transaction" << "\n";
        std::cin >> trans;
}
 
Yung switch pwedeng pamalit sa if-else lalo na kung masyado mahaba/madami yung conditions. Pero pag pinag-karambola mo, mas mahirap unawain. Suggest ko, stick with either switch o if-else.

Pag naayos mo na at na-implement yung suggestion sa taas, pwede mo din i-sama ang while loop (until the user enters the correct option, o he wants to quit altogether)

Code:
// The option to quit is not included. You can add it later.
while (pin != 123) {
    std::cout << "Incorrect PIN. Please re-enter: " << std::flush;
   std::cin >> pin;
}
// Condition above was satisfied. Now proceed here.
while (trans != 1 || trans || != 2 ...etc) {
        std::cout << "                   Menu                              " << "\n";
        std::cout << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _" << "\n";
        std::cout << "[1] Balance Inquiry" << "\n";
        std::cout << "[2] Withdrawal" << "\n";
        std::cout << "[3] Quit" << "\n";
        std::cout << "Select Transaction" << "\n";
        std::cin >> trans;
}
thanks
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 710
    Views
  • 4
    Participants
Last reply from:
Petunia08

Trending Topics

Online now

Members online
1,275
Guests online
1,235
Total visitors
2,510

Forum statistics

Threads
2,280,236
Posts
28,996,068
Members
1,226,662
Latest member
MJ08Mapagmahal
Back
Top