hw5fncts.cpp

// Programmer: Jennifer Leopold date: September 25, 2014

// File: hw5fncts.cpp

// Purpose: This file contains the definitions of the functions

// used in the health calculations program.

#include <string>

#include "hw5.h"

#include <iostream>

using namespace std;

void greet()

{

cout << "\nWelcome to " << MACHINE_NAME << endl;

return;

}

float bodyMassIndex(const short weight, const short height)

{

return((static_cast<float>(weight)/(height*height)) *

BODY_MASS_INDEX_MULTIPLIER );

}

float creatineClearance(const short age, const short weight,

const float serumCreatine)

{

return((static_cast<float>((CREATININE_CLEARANCE_YEARS-age) *

weight)/CREATININE_CLEARANCE_SERUM_DIVISOR) *

serumCreatine);

}

float coronaryRisk(const float bodyMassIndex,

const bool heartDiseasePredisposition,

const short poundsBaconEaten)

{

return(((bodyMassIndex > CORONARY_RISK_BMI_THRESHOLD)? 2 : 0) +

(heartDiseasePredisposition? 1 : 0) +

poundsBaconEaten);

}

float totterIndex(const float leftLegLength,

const float rightLegLength)

{

return((rightLegLength == 0)? 0 :

(leftLegLength/rightLegLength));

}

float promptForNonNegativeFloat(string prompt)

{

bool invalidInput; // true when input <= 0

float inputValue; // user's input

do

{

cout << "Please enter a value greater than "

<< "zero for " << prompt << ": ";

cin >> inputValue;

invalidInput = inputValue <= 0;

if (invalidInput)

cout << "Invalid input!\n";

} while (invalidInput);

return(inputValue);

}

float promptForNonNegativeOrZeroFloat(string prompt)

{

bool invalidInput; // true when input < 0

float inputValue; // user's input

do

{

cout << "Please enter a value greater than "

<< "or equal to zero for " << prompt << ": ";

cin >> inputValue;

invalidInput = inputValue < 0;

if (invalidInput)

cout << "Invalid input!\n";

} while (invalidInput);

return(inputValue);

}

short promptForNonNegativeShort(string prompt)

{

bool invalidInput; // true when input <= 0

short inputValue; // user's input

do

{

cout << "Please enter a value greater than "

<< "zero for " << prompt << ": ";

cin >> inputValue;

invalidInput = inputValue <= 0;

if (invalidInput)

cout << "Invalid input!\n";

} while (invalidInput);

return(inputValue);

}

short promptForNonNegativeOrZeroShort(string prompt)

{

bool invalidInput; // true when input < 0

short inputValue; // user's input

do

{

cout << "Please enter a value greater than "

<< "or equal to zero for " << prompt << ": ";

cin >> inputValue;

invalidInput = inputValue < 0;

if (invalidInput)

cout << "Invalid input!\n";

} while (invalidInput);

return(inputValue);

}

bool promptForBool(string prompt)

{

bool invalidInput; // true when input not 'y' or 'n'

char inputValue; // user's input

do

{

cout << "Do you have " << prompt << "? (y/n) ";

cin >> inputValue;

invalidInput = (inputValue != 'y') && (inputValue != 'n');

if (invalidInput)

cout << "Invalid input!\n";

} while (invalidInput);

return(inputValue == 'y');

}

void goodbye()

{

cout << "\nThank you for using " << MACHINE_NAME << endl;

cout << "Goodbye...\n";

return;

}