Answer to Question #12881 in C++ for shalennee

Question #12881
You are required to calculate and display the fee for a bus passenger. The fee for an adult is RM15.00 and a child is RM8.00 each. However, an adult 50 years old and above will get 10% discount from the adult fee. The bus provides 20 seats for adults, 7 seats for adult above 50 years old and 13 seats for children.
1
Expert's answer
2012-08-10T09:26:52-0400
#include <iostream>
using namespace std;

int main (){
int allOfTickets = 40;
int child = 13, adult = 20 , adultAbove = 7;
int mark = 0;
do {
&
& if (mark == 1) {
& if (child == 0) cout<<"Sorry it's out of tickets\n";
& else {
& cout<< "RM8.00 ticket for child\n";
& child--; allOfTickets--;
& }
&
& } else if (mark == 2) {
& if (adult == 0) cout<<"Sorry it's out of tickets\n";
& else {
& cout<< "RM15.00 ticket for adult\n";
& adult--; allOfTickets--;
& }
& } else if (mark == 3) {
& if (adultAbove == 0) cout<<"Sorry it's out of tickets\n";
& else{
& cout<< "RM13.50 ticket for adult above 50 year\n";
& adultAbove--; allOfTickets--;
& }
& }
& cout<<"If you need ticket for child ENTER - 1\nIf you need ticket for adult ENTER - 2\nIf you need ticket for adult above 50 year ENTER - 3\nExit ENTER - Ctrl+Z\n";
&
} while (allOfTickets > 0 && cin>>mark);

return 0;
}

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

Chalton
15.09.14, 08:54

I like the way it was answered...its easily understandable...thank you

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS