🔒 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
  • 714
    Views
  • 4
    Participants
Last reply from:
Petunia08

Trending Topics

Online now

Members online
420
Guests online
1,298
Total visitors
1,718

Forum statistics

Threads
2,292,338
Posts
29,076,117
Members
1,210,293
Latest member
jjjjonas
Back
Top