https://rentry.org/PPP2_p102a

// Code derived from Stroustrup's PPP2 book
// § 4.4.1.1 if-statements
// -beginning on p 102

#include <iostream>

using std::cin;
using std::cout;

int main()
{
  int a = 0;
  int b = 0;

  cout << "Please enter two integers\n";
  cin >> a >> b;

  if (a < b)  // condition
    // 1st alternative (taken if condition is true):
    cout << "max(" << a << "," << b << ") is " << b << "\n";
  else
    // 2nd alternative (taken if condition is false):
    cout << "max(" << a << "," << b << ") is " << a << "\n";
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_04/main_p102a.cpp && ./a.out

PrevUpNext

Edit
Pub: 26 Jan 2023 08:04 UTC
Edit: 29 Apr 2023 06:57 UTC
Views: 623