#44924: cpp easy answer


1121232@stu.wghs.tp.edu.tw (Ian911436)


#include <iostream>

using namespace std;

int main() {
    // 輸入年齡
    int age;
    cin >> age;

    // 判斷票價
    int ticket_price = (age >= 0 && age <= 5) ? 0 :
        (age >= 6 && age <= 11) ? 590 :
        (age >= 12 && age <= 17) ? 790 :
        (age >= 18 && age <= 59) ? 890 :
        (age >= 60) ? 399 : -1;

    // 若票價為 -1,表示年齡無效
    if (ticket_price == -1) {
        cerr << "年齡輸入無效" << endl;
        return 1;
    }

    // 輸出票價
    cout << ticket_price << endl;

    return 0;
}