Answer to Question #156966 in C++ for Raihan Afryna binti Raizam

Question #156966

Function travelCharge(char,int,int): this function will calculate and return the traveling

cost based on the given table.


Vacation Places Places ID Adult (RM) Children (RM)

Pangkor Island P 350 175

Bukit Merah B 200 100

Teluk Batik T 80 40


1
Expert's answer
2021-01-22T18:25:55-0500
// The function will calculate and return the traveling
// cost to the Vacation Places.
// On incorrect input return -1
int travelCharge(char ID, int adults, int children) {
    if (adults < 0 || children < 0)
        return -1;
        
    int charge;
    switch (ID) {
        case 'P':       // Pangkor Island
            charge = 350*adults + 175*children;
            break;
        case 'B':       // Bukit Merah
            charge = 200*adults + 100*children;
            break;
        case 'T':       // Teluk Baltik
            charge = 80*adults + 40*children;
            break;
        default:
            charge = -1;                                  
    }
    return charge;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment