Husna Dental is a personal dental clinic that recently operated on 1st January 2015. The payment for dentistry services at Husna Dental is different based on the type of treatment and patient status.
Patient Status
Restoration (1)
Extraction(2)
Scaling(3)
Children(C)
RM6.00
RM15.50
RM4.00
Adult(A)
RM7.50
RM18.00
RM5.00
Due to the opening ceremony, the discount of 20% will be given for children’s treatment and 15% discount for adult’s treatment.
Write a C++ program that performs the following.
· · · ·
Reads the patient's name, patient status, and type of treatment.
Displays the appropriate message when the user enters an invalid status. Calculates the payment before and after discount.
At the end of the program, displays receipt that contain patient’s name and her/his total payment after discount.
Write in 2 version of selction syntax using if..else and switch..case
#include <iostream>
#include <string>
using namespace std;
int main()
{
int person;
int type;
cout << "1. Restoration" << endl;
cout << "2. Extraction" << endl;
cout << "3. Scaling" << endl;
cout << "Enter type of treatment: ";
cin >> type;
if (type < 1 || type > 3)
{
cout << "Wrong choice!" << endl;
system("pause");
return 0;
}
cout << "1. Adult" << endl;
cout << "2. Children" << endl;
cout << "Enter type of person: ";
cin >> person;
if (person < 1 || person > 2)
{
cout << "Wrong choice!" << endl;
system("pause");
return 0;
}
cout << "Enter person name: ";
string name;
cin >> name;
double discount = 0;
switch (person)
{
case 1:
{
discount = 0.15;
break;
}
case 2:
{
discount = 0.2;
break;
}
default:
break;
}
double totalCost = 0;
switch (type)
{
case 1:
{
if (person == 1)
{
totalCost = 7.5;
}
else totalCost = 6;
break;
}
case 2:
{
if (person == 1)
{
totalCost = 18;
}
else totalCost = 15.5;
break;
}
case 3:
{
if (person == 1)
{
totalCost = 5;
}
else totalCost = 4;
break;
}
default:
break;
}
cout << name << " total cost is: RM" << totalCost << " with discount: RM" << totalCost * (1 - discount) << endl;
system("pause");
if (person == 1) discount = 0.15;
else discount = 0.2;
if(type == 1)
{
if (person == 1)
{
totalCost = 7.5;
}
else totalCost = 6;
}
else if (type == 2)
{
if (person == 1)
{
totalCost = 18;
}
else totalCost = 15.5;
}
else
{
if (person == 1)
{
totalCost = 5;
}
else totalCost = 4;
}
cout << endl;
cout << name << " total cost is: RM" << totalCost << " with discount: RM" << totalCost * (1 - discount) << endl;
system("pause");
return 0;
}
Comments
Leave a comment