📄 dentalpayment.cpp
字号:
// Exercise 5.12: DentalPayment.cpp
// This application calculates the total cost of the bill for a
// patient at a dental office.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required for parameterized stream manipulators
#include <string> // required to access string functions
using namespace std; // for accessing C++ Standard Library members
// function main begins program execution
int main()
{
// define variables
string patient; // patient name
char cleaning = 'n'; // 'y' if cleaning was performed
char filling = 'n'; // 'y' if filling was performed
char xRay = 'n'; // 'y' if x-ray was performed
// prompt user for and input patient name
cout << "\nEnter patient name: ";
getline( cin, patient );
// display error message if no name is entered
if ( patient.size() == 0 )
{
// display error message
cout << "\nError: You must enter a name\n" << endl;
} // end if
else // otherwise, do calculations
{
// prompt user for services performed
cout << "Was cleaning performed (y = yes, n = no)? ";
cin >> cleaning; // place user response in char cleaning
cout << "Was cavity filling performed (y = yes, n = no)? ";
cin >> filling; // place user response in char filling
cout << "Was an x-ray performed (y = yes, n = no)? ";
cin >> xRay; // place user response in char xRay
// display error message if no services are selected
if ( ( cleaning != 'y' ) && ( filling != 'y' ) &&
( xRay != 'y' ) )
{
// display error message
cout << "\nError: Select at least one service\n" << endl;
} // end if
else // otherwise, do calculation
{
double total = 0.0; // sum of all services performed
// if patient had a cleaning
if ( cleaning == 'y' )
{
total += 35; // add 35 to total
} // end if
// if patient had cavity filled
if ( filling == 'y' )
{
total += 150; // add 150 to total
} // end if
// if patient had x-ray taken
if ( xRay == 'y' )
{
total += 85; // add 85 to total
} // end if
// specify output format
cout << fixed << setprecision( 2 );
// display total bill
cout << "\nTotal: $" << total << endl << endl;
} // end inner else
} // end outer else
return 0; // indicate that program ended successfully
} // end function main
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -