Conditional operator: ?

This example reads in two numbers and finds the smallest. Notice that the result of the conditional operator is assigned to small.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Find smallest
#include <iostream>
using namespace std;
int main() { 
  double num1,num2,small;
  cout<<"Enter a number:";
  cin>>num1;
  cout<<"Enter another number:";
  cin>>num2;
  small=(num1<num2)? num1: num2;
  cout<<"smallest is "<<small<<endl;
  system("pause");
  return 0;
} // main
CODE

NEXT: Finds smallest and largest