KBJ tourist agency Sdn. Bhd wants you to write an application program to calculate the total price for their customers for a package of vacation. The following table shows the price for three destinations (transportation and accommodation) offered by the agency:
Destination Transportation Accommodation
Pulau Redang Child RM15.00
Adult RM30.00 RM95 per day
Pulau Perhentian Child RM20.00
Adult RM30.00 RM100 per day
Pulau Kapas Child RM10.00
Adult RM20.00 RM120 per day
This agency company will give some discount to a group of customers with is:
a. 10% discount will be given for the group that has a least 5 adults.
b. 25% discount will be given for the group that has more than 5 persons (adults and children)
c. 30% discount will be given for the group that has at least 15 persons.
Your application program has to display the output using this following screen layout:
KBJ TOURIST CUSTOMER INFORMATION
Customer’s name: XXXXXXXXXXXXX
Number of Children: XXXXX
Number of Adult: XXXXX
Transportation: RMXXX.XX
Accommodation: RMXXX.XX
Total price: RMXXXX.XX
this is the code i got so far but it doesnt work..:(
#include <iostream.h>
int main ()
{
char customerName,code,A,B,C;
int childNum,adultNum;
double rate,discount,totalPrice,a,c;
const double PriceA=95.00;
const double PriceB=100.00;
const double PriceC=120.00;
cout<<"Enter Your Name:"<<endl;
cin>>customerName;
cout<<"Enter The Number of Children:"<<endl;
cin>>childNum;
cout<<"Enter The Number of Adult:"<<endl;
cin>>adultNum;
cout<<"*Package Destination Package Code*"<<endl;
cout<<"*Pulau Redang:A*"<<endl;
cout<<"*Pulau Perhentian:B*"<<endl;
cout<<"*Pulau Kapas:C*"<<endl;
cout<<"Choose Your Destination By Enter The Code:"<<endl;
cin>>code;
if (code=='A'||code=='a')
{
a=adultNum*30.00;
c=childNum*15.00;
rate=PriceA;
}
else if (code=='B'||code=='b')
{
a=adultNum*30.00;
c=childNum*20.00;
rate=PriceB;
}
else if (code=='C'||code=='c')
{
a=adultNum*20.00;
c=childNum*10.00;
rate=PriceC;
}
else
{
cout<<"Please Enter A Valid Code"<<endl;
}
if (adultNum==5)
{
discount=0.1;
}
else if (adultNum && childNum>5)
{
discount=0.25;
}
else if (adultNum && childNum>=15)
{
discount=0.3;
}
totalPrice=((a+c)-discount)+rate;
cout<<"\n====================================================="<<endl;
cout<<"\nCustomer's Name:"<<customerName<<endl;
cout<<"\nNumber of Children:"<<childNum<<endl;
cout<<"\nNumber of Adult:"<<adultNum<<endl;
cout<<"\nTransportation:"<<code<<endl;
cout<<"\nAccommodation:"<<rate<<endl;
cout<<"Total Price Is RM"<<totalPrice<<endl;
cout<<"\n====================================================="<<endl;
That is a fail. It looks at 'a' first. If 'a' converts to false, then the result is false. Only if 'a' converts to true, the rest is evaluated, and the rest is 'b<c'. That is a boolean too. You probably did mean: (a+b) < c
I don't understand discount "a". It seems to apply to only one very specific case.
Your equation for totalPrice is way of from how percentages operate.
my problem now,it cannot run,when i try to run,it only can run to enter the name,then the rest are not...guysss,,help me..this is my first time to study this kind of subject,c++.
char customerName;
cout<<"Enter Your Name:"<<endl;
cin>>customerName;
Line 3 extracts only one non-whitespace character from stream -- the first letter that you write.
Even if you would have std::string customerName, you would still get only the first word. Study std::getline.
Yes, your code is wrong. I did point to one error in my previous post.
If you understand nothing and we correct your code, then you still understand nothing. That is not the purpose of your study, and it is complete waste of our time.
int main ()
{
const int max=100;
char customerName[max],code;
int childNum,adultNum,ac;
double rate,discount,totalPrice,a,c;
const double PriceA=95.00;
const double PriceB=100.00;
const double PriceC=120.00;
cout<<"Enter Your Name:"<<endl;
cin.getline(customerName,max);
cout<<"Enter The Number of Children:"<<endl;
cin>>childNum;
cout<<"Enter The Number of Adult:"<<endl;
cin>>adultNum;
cout<<"*Package Destination Package Code*"<<endl;
cout<<"*Pulau Redang:A*"<<endl;
cout<<"*Pulau Perhentian:B*"<<endl;
cout<<"*Pulau Kapas:C*"<<endl;
cout<<"Choose Your Destination By Enter The Code:"<<endl;
cin>>code;
ac=childNum+adultNum;
if (code=='A'||code=='a')
{
a=adultNum*30.00;
c=childNum*15.00;
rate=PriceA;
}
else if (code=='B'||code=='b')
{
a=adultNum*30.00;
c=childNum*20.00;
rate=PriceB;
}
else if (code=='C'||code=='c')
{
a=adultNum*20.00;
c=childNum*10.00;
rate=PriceC;
}
else
{
cout<<"Please Enter A Valid Code"<<endl;
}
double tP=a+c+rate;
if (adultNum==5)
{
discount=0.1;
totalPrice=tP*discount;
}
else if (ac>5)
{
discount=0.25;
totalPrice=tP*discount;
}