c++ function

this is my question::)
Lalala Playland offers great discounts for entrance tickets during the school holidays. The following are the prices and discounts given for children and adults.
Category Normal Price (RM) Discount (%)
Children (C) 45.00 20%
Adult (A) 5.00 5%

Write a function definition for function named price( ) that receives categories in character code and quantity. The function will calculate and return the TotalPrice.

Write a function definition for function named Discount( ) that receives categories in character code and quantity. The function will calculate and return the PriceDisc.

Write a main function which prompts the user to input the category and quantity. The program will call the above function to calculate the total price after the discount. Print the receipt which displays the quantity and the total price that need to be paid by each customers as shown below:

***after if run the code, the price is 0 for any q.

#include<iostream>
#include<iomanip>
using namespace std;
double price(char code,int q)
{
double TotalPrice;
if(code=='c'||code=='C') {double TotalPrice=45.00*q;};
if(code=='a'||code=='A') {double TotalPrice=5.00*q;};
return TotalPrice;
}
double Discount(char code,int q)
{
double PriceDisc;
if(code=='c'||code=='C') {double PriceDisc=((45.00*20)/(100))*q;};
if(code=='a'||code=='A') {double PriceDisc=((5.00*5)/(100))*q;};
return PriceDisc;
}
int main()
{
char codec,codea; int qc,qa; double tpadC,tpadA;
double pc,pa,dc,da;
cout<<"Press C for children: ";cin>>codec;
cout<<"enter quantity: ";cin>>qc;
cout<<"Press A for adult: ";cin>>codea;
cout<<"enter quantity: ";cin>>qa;
pc=price(codec,qc);pa=price(codea,qa);dc=Discount(codec,qc);da=Discount(codea,qa);
tpadC=pc-dc;tpadA=pa-da;
system("cls");
cout<<fixed<<setprecision(2);
cout<<"**************** RECEIPT ***************\n";
cout<<" CATEGORY QUANTITY PRICE\n";
cout<<"----------------------------------------\n";
cout<<" CHILDREN"<<" "<<qc<<" RM "<<tpadC;
cout<<"\n ADULT"<<" "<<qa<<" RM "<<tpadA;
cout<<"\n----------------------------------------\n";
cout<<" TOTAL"<<" RM"<<tpadC+tpadA;
return 0;
}
this is my question::)


There's no question there.
Topic archived. No new replies allowed.