https://rentry.org/PPP2_p95 ⎗ ✓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24// Code derived from Stroustrup's PPP2 book // § 4.3 Expressions // -beginning on p 95 #include <iostream> using std::cout; int main() { // compute area: int length = 99; // assign 99 to length int width = 40; int area = length * width; // a multiplication int perimeter = (length + width) * 2; // add then multiply // int perimeter = length * 2 + width * 2; // (clumsy) // int perimeter = length + width * 2; // add width * 2 to length (error) cout << length << '\n' // output above variable values to console... << width << '\n' // << area << '\n' // << perimeter << '\n'; } build & run: g++ -std=c++20 -O2 -Wall -pedantic ./ch_04/main_p95.cpp && ./a.out sauce: Bjarne Stroustrup's PPP2 textbook /robowaifu/'s official C++ learning textbook thread Prev • Up • Next