Solution
//File: main.cpp
//Purpose: This program serves as a receptionist for Dr. Nick's surgury patients.
#include<iostream>
using namespace std;
const float SURGURY_COST = 129.95;
const int MIN_AGE = 21;
const int MAX_AGE = 122; //Methusila
const int MAX_SUIT_AGE = 65;
int main()
{
// ======= Declarations =======
string name;
int age;
float cash;
bool lawsuit;
int surguries;
bool runProgram = true;
bool badInput;
char input;
int maxSurguries;
// ======= Output Formatting =======
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// ======= Welcome =======
cout<<"***** Dr. Nick's Surgury Receptionist *****"<<endl<<endl;
// ======= Input Name =======
while(runProgram)
{
cout<<"What is your name?"<<endl;
cin>>name;
// ======= Input Cash =======
do
{
cout<<name<<", how much cash do you have on you?"<<endl;
cin>>cash;
if(cash < 0)
cout<<"You can't carry debt on you, input a positive number"<<endl;
} while(cash < 0);
// ======= Check Cash =======
if(cash == 0)
cout<<"Leave immediately...and have a good day. NEXT."<<endl;
else if(cash < SURGURY_COST)
cout<<"Come back when you have at least $"<<SURGURY_COST<<"."<<endl;
else
{
// ======= Input Age =======
do
{
cout<<"How old are you?"<<endl;
cin>>age;
if(age < 0)
cout<<"You are not born yet? Try again."<<endl;
if(age > MAX_AGE)
cout<<"Call Guinness World Records."<<endl;
} while(age < 0 || age > MAX_AGE);
// ======= Check Age and Lawsuit Status =======
if(age < MIN_AGE)
{
cout<<"Please leave. You're too young!"<<endl;
}
else
{
if(age <= MAX_SUIT_AGE)
{
do
{
badInput = false;
cout<<"Have you ever filed a malpractice suit? (y/n)"<<endl;
cin>>input;
if(input == 'y' || input == 'Y')
{
lawsuit = true;
}
else if(input == 'n' || input == 'N')
{
lawsuit = false;
}
else
{
cout<<"Enter y or n"<<endl;
badInput = true;
}
} while(badInput);
}
else //They are above the MAX_SUIT_AGE
lawsuit = false;
// ======= Calculate Cost =======
if(lawsuit)
{
cout<<"Sorry, we're closed now!"<<endl;
}
else
{
do
{
cout<<"Surguries are $"<<SURGURY_COST
<<" each. How many would you like today?"<<endl;
cin>>surguries;
if(surguries < 0)
cout<<"Um, you need at least one. For your brain."<<endl;
} while(surguries < 0);
maxSurguries = cash/SURGURY_COST; //You don't actually need the cost
// ======= Display Results =======
if(surguries > maxSurguries)
cout<<"You can only afford "<<maxSurguries<<" surgur"
<<(maxSurguries == 1 ? "y" : "ies")<<". Come on in."<<endl;
else if(surguries == maxSurguries)
cout<<"Come on in."<<endl;
else
cout<<"You can still afford "<<maxSurguries - surguries<<" more "
<<"surgur"<<(maxSurguries - surguries == 1 ? "y" : "ies")
<<" after these. Good. You may need them."<<endl;
}
}
}
// ======= Check for Other Patients =======
do
{
badInput = false;
cout<<"Anyone else out there? (y/n)"<<endl;
cin>>input;
if(input == 'y' || input == 'Y')
{
runProgram = true;
}
else if(input == 'n' || input == 'N')
{
runProgram = false;
}
else
{
cout<<"Enter y or n"<<endl;
badInput = true;
}
} while(badInput);
}
cout<<"See you later."<<endl<<endl;
return 0;
}