/** * cond.cpp * 19-mar-2007/sklar * * demonstrates the use of * -- the cmath library * -- assignment operator * -- conditional operator * */ #include #include #include #include using namespace std; int main() { double x; double y; bool negative; srand( time( NULL )); x = rand() % 360; x *= M_PI / 180; cout << "x=" << x << endl; y = sin( x ); cout << "y=" << y << endl; // here's the if-else way /* if ( y < 0 ) { negative = true; } else { negative = false; } */ // here's the use of the "conditional operator" negative = ( y < 0 ) ? true : false; if ( negative ) { cout << "negative sin\n"; } else { cout << "positive sin\n"; } } // end of main()