NuMetro has a special on movies for all members of the public but special discounts for students and pensioners. If
pensioners or students buy a movie ticket they receive 10% if they buy a movie and popcorns, they receive 20%
discount. Other customers only receive a discount when they buy a movie ticket and popcorn; there is no discount for
just a movie ticket alone.
Write a program named question5b.cpp that will consist of two functions. The program must prompt the user for type of
customer (‘p’ for pensioner, ‘s’ for student, ‘o’ for other). It must then call the relevant function according to that entry.
The first function must receive the customer type and calculates discount for pensioners and students. The second
function calculates the discount for customers that are not pensioners or students.
#include<iostream>
using namespace std;
double pensioners_student_ticket(){
double total;
char c;
cout<<"Do you want to buy popcorns (y/n)?";
cin>>c;
if(c=='y'){
total = 80 - (0.2 * 80);
}
else{
total = 80 - (0.1 * 80);
}
return total;
}
double other_customers(){
double total;
char c;
cout<<"Do you want to buy popcorns (y/n)?";
cin>>c;
if(c=='y'){
total = 80 - (0.05 * 80);
}
else{
total = 80;
}
return total;
}
int main(){
cout<<"Enter user type:Â customer ('p' for pensioner,'s' for student, 'o' for other)\n";
char type;
cin>>type;
if(type=='p'|| type=='s'){
cout<<"The final amount that is due for the movie ticket is:Â "<<pensioners_student_ticket()<<endl;
}
else if(type=='o'){
cout<<"The final amount that is due for the movie ticket is:Â "<<other_customers()<<endl;
}
}
Comments
Leave a comment