# 0 s st va outputwarningvalue lu return false ou cal

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: uble logVal); void outputOneResult(char resultName, double value, double result); void main() { double userValue; double sine, cosine, logarithm; userValue = queryUserForValue(); generateResults(userValue, sine, cosine, logarithm); outputResults(userValue, sine, cosine, logarithm); } CS 140 Chapter 4 Page 12 double queryUserForValue() { double nbr; qu er cout << "Enter the number to be tested: "; yU cin >> nbr; se while (!testValueBounds(nbr)) rF te cin >> nbr; st cal orV Va ls al return nbr; lu } ue eB ou bool testValueBounds(double value) { nd te if (value <= 0.0) s st { Va outputWarning(value); lu return false; ou } cal eBou return true; tp nd } ut ls s Wa void outputWarning(double value) rn { in cout << "BAD VALUE: " << value << endl; g cout << "(Only positive values are allowed!)" << endl << endl; return; } CS 140 Chapter 4 Page 13 void generateResults(double val, double &sinVal, double &cosVal, double &logVal) { double valAsRadians = val * 3.1415926535 / 180; sinVal = sin(valAsRadians); cosVal = cos(valAsRadians); logVal = log(val); return; } void outputResults(double val, double sinVal, double cosVal, double logVal) { cout << endl << endl << "The Mathematical Results:" << endl << endl; outputOneResult("Sine", val, sinVal); outputOneResult("Cosine", val, cosVal); outputOneResult("Logarithm", val, logVal); cout << endl << endl; return; } void outputOneResult(char resultName, double value, double result) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(5); cout << setw(9) << resultN...
View Full Document

## This note was uploaded on 08/26/2009 for the course CS 140 taught by Professor Staff during the Fall '08 term at Southern Illinois University Edwardsville.

Ask a homework question - tutors are online