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
// 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;
}
Comments
Leave a comment