How to make a program output which number is the maximum and minimal?
Hello. I understand that in this code line (a>b)?cout<<a:cout<<b; outputs a if a>b. But I'd like to understand what some things in this code line do. Why is a ? needed after(a>b) Why do we need a colon after a in <<a:cout<<b; Why doesn't b need a colon too? Isn't this code also saying to the program to output b? Thanks in advance! The program as it follows: #include <iostream> using namespace std; int main() { double a, b; cout << "Enter value for a:" << endl; cin >> a; cout << "Enter value for b:" << endl; cin >> b; cout << "a+b=" << a+b << endl; cout << "a-b=" << a-b << endl; cout << "a*b=" << a*b << endl; cout << "(a+b)/2=" << (a+b)/2 << endl; cout << "the max is "; (a>b)?cout<<a:cout<<b; cout << endl; cout << "the min is "; (a<b)?cout<<a:cout<<b; cout << endl; system("pause"); }